rewriting urls for static js and css files using nginx server

亡梦爱人 提交于 2019-12-20 03:00:28

问题


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;
}

回答1:


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;


来源:https://stackoverflow.com/questions/9423138/rewriting-urls-for-static-js-and-css-files-using-nginx-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!