mar*_*tom 3 redirect nginx url-rewriting nginx-location
我想将“.html”添加到以“/”结尾的每个文档中,主页除外。
\n\n我尝试了一些不同的方法,使用重写并使用 nginx 返回 301,但我没有\xc2\xb4t 无法使其工作。附上我所做的最后一个版本,它正在执行 /*/.html 但第二个 / 不应该在那里。
\n\nlocation / {\n try_files $uri $uri/ =404;\n return 301 $scheme://$host$request_uri.html;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我正在寻找的解决方案:
\n\nroot:domain.com 应作为 www.domain.com 传送
\n\n文件应重定向 (301) 到 *.html 版本
\n\n您将需要使用正则表达式来捕获尾随之前的 URI 部分/,以便消除它。一种解决方案是在try_files语句中使用命名位置。
例如:
location / {
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite ^(.+)/$ $1.html permanent;
}
Run Code Online (Sandbox Code Playgroud)
请参阅此文档了解更多信息。
| 归档时间: |
|
| 查看次数: |
4202 次 |
| 最近记录: |