Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;
}
like image 697
NoOneElse Avatar asked Jan 29 '26 14:01

NoOneElse


1 Answers

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;
like image 116
Dayo Avatar answered Feb 03 '26 04:02

Dayo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!