【问题标题】:rewriting urls for static js and css files using nginx server使用 nginx 服务器重写静态 js 和 css 文件的 url
【发布时间】:2012-03-14 10:53:32
【问题描述】:

我想用 nginx 重写 js 和 css 文件

我有这个网址模式

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 文件一样

我试图通过使用 thi 解决方案来解决这个问题,但我不起作用,它在重新启动 nginx 服务器时显示错误

location ~* \.(css|js) {
 rewrite /(.*)\.[\d]{10}\.(css|js) $1.$2 last;
}

【问题讨论】:

标签: url-rewriting nginx


【解决方案1】:

重写规则似乎有点过于复杂。

你可以试试这个:

rewrite /(.+/)\.+\.(css|js)$ /$1.$2 last;

如果你必须使用你原来的,你需要把它用引号引起来,因为它包括花括号......'{'和'}'

rewrite "/(.+)\.[\d]{10}\.(css|js)$" /$1.$2 last;

【讨论】:

    猜你喜欢
    • 2020-05-18
    • 1970-01-01
    • 1970-01-01
    • 2019-01-22
    • 1970-01-01
    • 2021-06-29
    • 2011-09-16
    • 2016-04-05
    • 1970-01-01
    相关资源
    最近更新 更多