Nginx merge_slashes 重定向 [英] Nginx merge_slashes redirect
本文介绍了Nginx merge_slashes 重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Java 应用程序中使用了 nginx,我的问题是 nginx 正在合并斜杠,但我无法将我的网站重定向到正确的版本.
I am using nginx in with my Java Application and my problem is that nginx is merging the slashes and I am unable to redirect my website to the correct version.
例如:
http://goout.cz/cs/koncerty///praha/
合并到
http://goout.cz/cs/koncerty/praha/
然后我无法识别格式错误的 URL 并执行重定向.
and then I am unable to recognized the malformed URL and perform the redirection.
我尝试设置
merge_slashes off;
然后:
rewrite (.*)//(.*) $1/$2 permanent;
但这没有效果,//保留在 URL 中.
But this has no effect and the // stays in the URL.
我怎样才能做到这一点?
How can I achieve this?
推荐答案
试试这个(未经测试):
Try this (untested):
merge_slashes off;
rewrite (.*)//+(.*) $1/$2 permanent;
如果有多组斜杠,它可能会导致多次重定向.
It might cause multiple redirects if there are multiple groups of slashes though.
像这样:
http://goout.cz/////cs/koncerty///praha/
可能去:
http://goout.cz/cs/koncerty///praha/
最后:
http://goout.cz/cs/koncerty/praha/
这篇关于Nginx merge_slashes 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文