NoOneElse
NoOneElse

Reputation: 1251

rewriting urls for static js and css files using nginx server

i would like to rewrite js and css files using nginx

i have this urls pattern

css : http://myhost.com/css/min/css_home.1330004285.css

js : http://myhost.com/js/min/js_home.1330004285.js

for the css files have to redirect to http://myhost.com/css/min/css_home.css and the same way for the js files

i tried to resolve this by using thi solution but i doesn't work , it showing me an error when restarting nginx server

location ~* \.(css|js) {
 rewrite /(.*)\.[\d]{10}\.(css|js) $1.$2 last;
}

Upvotes: 3

Views: 4671

Answers (1)

Dayo
Dayo

Reputation: 12775

The rewrite rule seems a bit over complicated.

You can try this:

rewrite /(.+/)\.+\.(css|js)$ /$1.$2 last;

If you have to use your original one, you need to wrap it in quotes because it includes curly braces ... '{' and '}'

rewrite "/(.+)\.[\d]{10}\.(css|js)$" /$1.$2 last;

Upvotes: 4

Related Questions