使用 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屋!