13

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?

5 Answers 5

14

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 https://stackoverflow.com/questions/1036941/setup-expires-headers-php-apache

Hope this helps:)

3
  • 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. Commented Dec 31, 2009 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. Commented Dec 31, 2009 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. Commented Feb 19, 2010 at 10:37
6

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/

1
  • 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. Commented Dec 31, 2009 at 18:08
2

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

change AllowOverride None

to AllowOverride FileInfo Options Indexes

1
  • 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. Commented Nov 11, 2010 at 7:38
0

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> 
0

I had the same problem on Apache 2.4 / CentOS 7. The Syntax for the Config File now is: "AllowOverride Options=Indexes"

<Directory /var/www/html/> Options Indexes FollowSymlinks AllowOverride Options=Indexes </Directory> 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.