When working with Apache 1.3 servers where you only have .htaccess access, the "ExpiresActive not allowed here" error typically stems from server configuration restrictions rather than incorrect syntax. The error occurs because the server administrator has disabled the ExpiresActive
directive at the directory level through AllowOverride
settings in httpd.conf.
To verify if this is indeed an AllowOverride
restriction:
# Try creating a test .htaccess file with:
Options +FollowSymLinks
<IfModule mod_expires.c>
# This should generate a different error if mod_expires isn't loaded
ExpiresDefault "access plus 1 hour"
</IfModule>
If you get a "mod_expires not available" error instead, the module isn't loaded. If you still see the "not allowed here" error, it's definitely an AllowOverride
limitation.
Since you mentioned mod_headers isn't available either, here are some alternative approaches:
1. PHP Header Alternative
For dynamic content, you can set cache headers directly in PHP:
<?php
header("Cache-Control: max-age=3600, public");
header("Expires: ".gmdate('D, d M Y H:i:s', time()+3600).' GMT');
?>
2. Using FilesMatch for Static Content
Try this pattern which sometimes bypasses restrictions:
<FilesMatch "\.(jpg|jpeg|png|gif|js|css)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
3. Leveraging mod_rewrite (If Available)
An unconventional approach using mod_rewrite:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.(css|js)$ - [E=Cache-Control:max-age=3600]
</IfModule>
To check what directives are allowed in .htaccess:
# Create a phpinfo.php file with:
<?php phpinfo(); ?>
Look for the "Loaded Modules" section and "AllowOverride" directives in the output.
If none of these workarounds succeed, your best options are:
- Contact your hosting provider to request mod_expires or mod_headers support
- Consider switching to a host with more flexible .htaccess capabilities
- Implement client-side caching through JavaScript service workers
When working with Apache 1.3 servers, you might encounter the frustrating "ExpiresActive not allowed here" error when trying to implement caching through .htaccess. This typically indicates a server configuration issue rather than a problem with your code.
The error occurs because the server administrator has restricted the use of ExpiresActive
directive in .htaccess files through the AllowOverride
setting in httpd.conf. In Apache configuration, certain directives require explicit permission to be used in .htaccess files.
# Example of restrictive AllowOverride in httpd.conf
AllowOverride None
# What you need is:
AllowOverride Indexes FileInfo
To confirm this is indeed the problem, you can:
- Check if mod_expires is loaded by creating a test.php file with:
<?php phpinfo(); ?>
- Look for 'Loaded Modules' section to verify mod_expires is present
- Examine error logs for more detailed information
If you don't have access to httpd.conf, consider these workarounds:
Option 1: Using mod_headers (if available)
<IfModule mod_headers.c>
Header set Cache-Control "max-age=3600, public"
</IfModule>
Option 2: PHP-based caching headers
<?php
header("Cache-Control: max-age=3600, public");
header("Expires: ".gmdate("D, d M Y H:i:s", time() + 3600)." GMT");
?>
Option 3: File-specific caching
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
When implementing caching headers:
- Set shorter cache times for HTML (1 hour)
- Longer cache for static assets (1 week to 1 year)
- Use file versioning for CSS/JS to force cache invalidation
- Test with tools like Google PageSpeed Insights
Use these curl commands to verify your headers:
curl -I http://yoursite.com/example.css
curl -v -H "Cache-Control: no-cache" http://yoursite.com