I am attempting to set the expire headers for Rails' auto-versioned assets, like whatever.css?1234567890 . (I'd rather not set the expire headers for unversioned assets.) In order to I possibly could find online involved two steps: 1) rewrite all web addresses that finish in 10 numbers to load from /public/add_expires_header rather than from /public, where add_expires_header is really a symlink that indicates /public 2) Add an expiry date to any or all files from add_expires_header.

Appears like advisable -- but passenger does not appear to identify the rewrite rule, as shown by the below curl results.

(Note: many people appeared to consider they might accomplish transpire using FilesMatch, however i read elsewhere that FilesMatch can't begin to see the query string.)


#from sites_enabled/sitename within the  tags

...

RewriteCond % ^[-9]$

RewriteRule ^(.*)$ /add_expires_header% [QSA]

  ExpiresActive On

  ExpiresDefault "access plus 1 years"

...

-----

#curl signifies that rewrite rule is not taking effect

manu@Edge-Server:~$ curl -I -L "http://site.com/stylesheets/style.css?1249092148"

HTTP/1.1 200 OK

Date: Tue, 11 August 2009 04:07:49 GMT

Server: Apache/2.2.11 (Ubuntu) Phusion_Passenger/2.2.4 PHP/5.2.6-3ubuntu4.1 with Suhosin-Patch

Last-Modified: Sitting, 01 August 2009 02:02:28 GMT

ETag: "455b-2fbb-4700aedc5f500"

Accept-Ranges: bytes

Content-Length: 12219

Vary: Accept-Encoding

Content-Type: text/css

manu@Edge-Server:~$ curl -I -L "http://site.com/add_expires_header/stylesheets/style.css?1249092148"

HTTP/1.1 200 OK

Date: Tue, 11 August 2009 04:07:55 GMT

Server: Apache/2.2.11 (Ubuntu) Phusion_Passenger/2.2.4 PHP/5.2.6-3ubuntu4.1 with Suhosin-Patch

Last-Modified: Sitting, 01 August 2009 02:02:28 GMT

ETag: "455b-2fbb-4700aedc5f500"

Accept-Ranges: bytes

Content-Length: 12219

Cache-Control: max-age=31536000

Expires: Get married, 11 August 2010 04:07:55 GMT

Vary: Accept-Encoding

Content-Type: text/css

I have also attempted such as the rewrite stuff in apache2.conf, httpd.conf, and public/.htacess

Any ideas?

Thanks!

I approach this by mixing it with utilizing an assets host on the separate subdomain to prevent the entire rewrite problem. That method for you to set the expire headers for everything on that subdomain. You are able to activate this in rails in conditions/production.rb.

If you won't want to opt for another subdomain I believe the code below must do it, although I haven't examined it myself:

ExpiresActive On
  <FilesMatch "\.(ico|gif|jpe?g|png|js|css)$">
    ExpiresDefault "access plus 1 year"
  </FilesMatch>