使用Nginx服务器重写静态js和CSS文件的url [英] rewriting urls for static js and css files using nginx server
问题描述
我想使用Nginx重写js和CSS文件
i would like to rewrite js and css files using nginx
我有这个网址格式
css:
http://myhost.com/css/min/css_home.1330004285.css
js:
http://myhost.com/js/min/js_home.1330004285.js
,因为css文件必须重定向到
http://myhost.com/css/min/css_home.css
和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
我尝试通过使用该解决方案来解决此问题,但我无法正常工作,它在重新启动Nginx服务器时向我显示了一个错误
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;
}
推荐答案
重写规则似乎有点复杂.
The rewrite rule seems a bit over complicated.
您可以尝试以下操作:
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;
这篇关于使用Nginx服务器重写静态js和CSS文件的url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!