Question about rewrite directive

rainer at rainer at
Thu Jan 28 14:12:16 UTC 2016


a customer has this in his .htaccess file (among other things):

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ $1.$3 [L]

This is to enable versioning of various files, so you can have long 
"Expires" on them and still update them as needed while retaining the 
old ones, if needed.

I want to deliver static files directly from nginx, so I created this:

     location ~* ^(.+)\.(\d+)\.(js|css|png|jpg|gif|gzip)$ {
                rewrite ^(.+)\.(\d+)\.(js|css|png|jpg|gif|gzip)$ $1.$3 ;
                expires 1h;

This works in most cases, except for files which already have a version 
number of some sort.
and two others from the jquery framework.

What's wrong with my nginx rewrite?
Because in apache, the rewrite rule works as intended.

nginx 1.8.0 on FreeBSD 10-amd64.


More information about the nginx mailing list