3

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;
}
NoOneElse
  • 1,101
  • 2
  • 11
  • 15
  • -@NoOneElse did you ever find a solution for this? It looks like you are trying to do what I and others have done with Apache using Nginx http://stackoverflow.com/questions/118884/what-is-an-elegant-way-to-force-browsers-to-reload-cached-css-js-files – tim peterson Dec 16 '13 at 22:58

1 Answers1

4

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;
Dayo
  • 12,413
  • 5
  • 52
  • 67