【发布时间】:2014-05-27 07:15:56
【问题描述】:
目前我正在使用以下配置文件来尝试将所有 URL 从 example.com/page.html 更改为 example.com/page.html。由于 SEO 原因,Page.html 应该不再可访问,它应该是一个非常简单的重定向。搜索后发现如下代码:
server {
listen myip8:8080;
root /mydir;
index index.html index.htm;
server_name example.com;
# example.com/index gets redirected to example.com/
location ~* ^(.*)/index$ {
return 301 $scheme://$host$1/;
}
# example.com/foo/ loads example.com/foo/index.html
location ~* ^(.*)/$ {
try_files $1/index.html @backend;
}
# example.com/a.html gets redirected to example.com/a
location ~* \.html$ {
rewrite ^(.+)\.html$ $scheme://$host$1 permanent;
}
# anything else not processed by the above rules:
# * example.com/a will load example.com/a.html
# * or if that fails, example.com/a/index.html
location / {
try_files $uri.html $uri/index.html @backend;
}
# default handler
# * return error or redirect to base index.html page, etc.
location @backend {
return 404;
}
但是,我遇到了问题。找不到我所有的静态资产。 CSS、JS 等只会给出 404 错误。
该代码中的什么可能导致 404?
另外,值得注意的是我的服务器设置。我有两个独立的 VPS。一个清漆和一个 Nginx。 Varnish 服务器代理对 Nginx 的请求。我不确定这是否与此有关。 最后,我找到代码的原始线程是这个:redirect /foo.html to /foo but not / to /index in nginx 它似乎在那里为 OP 工作,但我无法让它工作。
【问题讨论】:
标签: html redirect nginx varnish