Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to add Expires headers to the HTTP responses of the site I am working on. The only way for me to control the Apache 1.3 server is by editing my .htaccess file. I tried adding code such as the following to enable the Expires headers:

<IfModule mod_expires.c>
    ExpiresActive on
    ExpiresDefault "access plus 1 hour"
</IfModule>

However, this results in an internal server error with the following error message in the log:

ExpiresActive not allowed here

I probably cannot use alternative methods of cache control, since mod_headers is not enabled. Is there any way I can still enable the Expires header using mod_expires through some commands in the .htaccess file?

Update
I recall reading somewhere that the Override settings in httpd.conf might have something to do with it. Is there any way to validate that that is indeed the problem? If it is, is there some workaround to control caching headers for my website anyway?

share|improve this question

4 Answers 4

up vote 10 down vote accepted

On a general note, the simplest way to deal with issues like this is referring to the manual.

http://httpd.apache.org/docs/1.3/mod/mod_expires.html#expiresactive

Syntax:      ExpiresActive On|Off
Context:     server config, virtual host, directory, .htaccess
Override:    Indexes
Status:      Extension
Module:      mod_expires

The two fields of interest it Context and Override. As we can see its OK to use ExpiresActive in an .htaccess file aslong as you AllowOverride Indexes

Update:

To address your need for expire headers. Check out http://stackoverflow.com/questions/1036941/setup-expires-headers-php-apache

Hope this helps:)

share|improve this answer
    
Thanks for your response, but as my question already states: I don't have access to the server's configuration other than through the .htaccess file in my web root. So if the AllowOverride is not set correctly, I'm out of luck. –  Daan Dec 31 '09 at 18:09
    
You should talk to your provider about that. Not allowing Indexes is just imho stupid. And, yes, if they cant/wont change it then you struck out as far as mod_expires goes. –  Rune Nilssen Dec 31 '09 at 18:25
    
Just to echo Rune's point - if your service provider won't change their AllowOverride parameter then there's nothing else you can do. –  DaveG Feb 19 '10 at 10:37

Adding "AllowOverride Indexes" to Apache's conf for the folder where you have htaccess in worked for me. Found the solution here http://speedforce.org/2009/01/were-back/

share|improve this answer
1  
Thanks for your response, but as my question already states: I don't have access to the server's configuration other than through the .htaccess file in my web root. So if the AllowOverride is not set correctly, I'm out of luck. –  Daan Dec 31 '09 at 18:08

on RHEL in /etc/httpd/conf/httpd.conf

change AllowOverride None

to AllowOverride FileInfo Options Indexes

share|improve this answer
2  
Thanks for your response, but again, as my question already states: I don't have access to the server's configuration other than through the .htaccess file in my web root. So if the AllowOverride is not set correctly, I'm out of luck. –  Daan Nov 11 '10 at 7:38

In my case, mod_expires is not available, but headers_module is, this works nicely (on Apache 2.0):

# match all these file types, regardless of upper/lowercase
<FilesMatch "\.(?i:jpg|png|gif|js|css)$">
    # 60 seconds * 60 minutes * 24 hours * 7 days
    Header set Cache-Control "max-age=604800, public, must-revalidate"

    # alternative: never expire headers (do look up the caveats)
    # Header set Expires "Thu, 01 Jan 2030 08:08:00 GMT"
    # Header set Cache-Control "public, no-transform"

    # further (debatable) optimizations
    # FileETag None
    # Header unset ETag
    # Header unset Last-Modified
</FilesMatch>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.