如何配置重定向到 url 而不在 nginx 中添加斜杠? [英] How to configure redirects to url without trailing slash in nginx?
本文介绍了如何配置重定向到 url 而不在 nginx 中添加斜杠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将带有斜杠的 URL 重定向到不带斜杠的路径.所以/some-url/到/some-url 以解决重复内容问题
I want to redirect URLs with slash to the path without trailing slash. So /some-url/ to /some-url for Duplicate Content Issue
以及其余的网址,例如
/some-url.xml
/some-url?
/some-url/?
/some-url?q=v
/some-url/?q=v
/some-url
应该保持不变.我想与以下问题完全相反.如何配置重定向到带有斜杠的 urlnginx?
Should stay without redirection. i want exactly opposite to following question. How to configure redirects to url with trailing slash in nginx?
推荐答案
在验证所有 nginx 配置后,我没有找到任何 else 条件和任何 AND (&&) 条件.最后我在 nginx 中使用了set"属性
After verifying all the nginx configuration i dint find any else condition and any AND (&&) conditions. finally i did with "set" property in nginx
set $val 0;
if ($request_method ~ "^GET$"){
set $val 1;
}
if ($request_uri ~ ^/(.*)/$ ) {
set $val "${val}1";
}
location / {
if ($val ~ 11) { rewrite ^/(.*)/$ https://$host/$1; }
try_files $uri $uri/ /index.php$is_args$args;
}
这篇关于如何配置重定向到 url 而不在 nginx 中添加斜杠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文