Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The whole application has a global expires header set in the .htaccess I have a URL e.g. /current which I need like a different expiry header.

share|improve this question

Use could use <Location> apache directive to define different options (e.g. expire) for specific URL.

share|improve this answer
The URL is being rewritten, can I still use Location with this? – Tom May 10 '11 at 14:23
Following @AlexD answer, you can simply add the header at the new location – jflaflamme Jan 17 '12 at 16:02

Another solution could be to use Apache mod_setenvif and mod_headers to conditionally set cache headers.

Header set Cache-Control no-cache env=OVERRIDE_CACHE_HEADERS

I have not tried this specific configuration, but I have a similar one that sets environment variable with a RewriteRule directive and then uses Header to conditionally change Cache-Control directives

share|improve this answer

I'm assuming:

  1. You want all content inside some directory to have a different expire than the rest of the site--not just a few files. For example: Dynamically generated JS files; frequently changing logo and other images files; or often edited CSS that you want very short cache lifetimes for..
  2. Apache is directly serving up that content--it's not a view folder or something for a framework which PHP is including out of.
  3. You have the mod_expires module enabled

.htaccess files are searched for in every directory along the way to the file being served up if they're enabled starting at the docroot. Therefore, the easiest would be to put a new .htaccess file in the directory for which you wish to change the expire limit. If your site is and you want /current to have a different expire header a simple .htaccess file in The file just needs:

# enable expirations with mod_expires
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 2 weeks"

This being said... a block in your httpd.conf file(s) for the entire server, a virtual host block, or in the docroot's .htaccess would be more elegant and manageable solutions.

share|improve this answer
What about if I wanted different rewrite rules to have different expires? e.g. /page vs /event ? – Tom Jan 23 '12 at 7:02
If /page and /event are different directories, just put a custom .htaccess in each. Also if you want it more centralized, create a <location> block for each in a central .htaccess or httpd.conf file. Location blocks are like if checks on a url, if they match, the configuration lines inside the block are applied, otherwise they're skipped. The way I usually roll is to first get it working with the .htaccess files in the desired directories. Then convert them to location blocks in the docroot .htaccess file (that way you avoid .htaccess file pollution!) – Ray Jan 23 '12 at 15:28

Your Answer


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.