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've borrowed some mod_expires code from the HTML5 Boilerplate that adds some sensible defaults for asset expiry (I have filename version revving configured with htaccess so I can add mtimes before asset extensions like script.123456789.js):

ExpiresActive on
ExpiresDefault                                      "access plus 1 month"

# CSS
ExpiresByType text/css                              "access plus 1 year"

# Data interchange
ExpiresByType application/json                      "access plus 0 seconds"
ExpiresByType application/xml                       "access plus 0 seconds"
ExpiresByType text/xml                              "access plus 0 seconds"

# ... etc ...

However, I'd like to disable these on my development server (which sets a DEVELOPMENT=1 environment variable). Is it possible to conditionally disable mod_expires (perhaps ExpiresActive On) in 2.4.4 like you can with mod_access if an environment variable is set (Allow from env=DEVELOPMENT) ?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

I don't know any easy way of doing this based on the value of an environment variable. You might be able to figure out a way with mod_rewrite, but it would be ugly.

An easier method is to have your development server set a command-line switch, -DDEVELOPMENT, for Apache, instead of (or in addition to) the environment variable. Then the Apache config becomes trivial:

<IfDefine !DEVELOPMENT>
ExpiresActive on
...
</IfDefine>

The right place to set the switch depends on your distro. In Debian & family, you set

export APACHE_ARGUMENTS=-DDEVELOPMENT

in /etc/apache2/envvars. In RHEL, you set

OPTIONS=-DDEVELOPMENT

in /etc/sysconfig/httpd.

share|improve this answer
    
+1 This is genius! Plus it's part of the core so my host won't choke on <IfDefine>. Many thanks! –  PhpMyCoder Jul 14 '13 at 6:48
    
Good :) One thing to add is that command-line switches apply to all virtual hosts on your server. But for something general like -DDEVELOPMENT that's probably fine. –  Andrew Schulman Jul 14 '13 at 10:29

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.