htaccessinifinte循环当试图添加/? - htaccess inifinte loop when trying to add “/”

- 此内容更新于:2015-12-20
主题:

我想添加“/”的url,它被自动完成目录,但我还想做非现有的目录,我使用漂亮的页面的url是我想说的是如果request_uri没有”。”,不以“/”重定向到request_uri/发生什么我得到一个重定向从mylinkmylink/像预期的那样,但它会继续所以我最终mylink//////////(10浏览器检测到无限循环)我想有我的正则表达式的问题,但我只是不能算出来。

原文:

I want to add "/" at the end of the url, it is being done automatically for directories but i also want to do it for non existing directories, which i use for pretty page url's

RewriteCond %{REQUEST_URI} [^\.].*[^/]$
RewriteRule .? %{REQUEST_URI}/ [R=301,L]

What i think it says is if request_uri has no "." in it and doesn't end with a "/" redirect to request_uri/

What happens is i get a redirect from mylink to mylink/ as expected but it keeps going so i end up with mylink////////// (at 10 browser detects infinite loop)

I guess theres a problem with my regex but i just can't figure it out.

解决方案:
您可以使用以下:这将一个末尾斜杠添加到重定向url。你的文章中描述的问题你有点不同。无限循环的错误是当一个url指向本身,及代码是正确的,它成功地添加一个末尾斜杠。你的其他规则可能与这一冲突。
原文:

You can use the following :

RewriteCond %{REQUEST_URI} /([^./]+)$
RewriteRule ^ %{REQUEST_URI}/ [R=301,L]

This adds a trailing slash to the redirected url. The issue you described in your post is a little diffrent. Infinite loop error is when a url is pointing to itself, your orignal code is correct ,it successfully adds a trailing slash .your other rules may be conflicting with this one.

网友:这仍然是过多的黑色魔法对我来说我认为浏览器缓存是参与这个问题因为我反复测试相同的url与不同的规则,现在只是工作。

(原文:This is still too much black magic for me i think browser cache was involved in the issue since i test same url with different rules over and over and now it just works.)