【发布时间】:2010-06-21 07:37:49
【问题描述】:
我将 mod_rewrite/.htaccess 用于漂亮的 URL。
我正在使用此条件/规则来消除尾部斜杠(或者更确切地说:通过 301 重定向重写为非尾部斜杠 URL;我这样做是为了避免重复的内容,并且因为我喜欢带有没有斜线更好):
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^\.localhost$ [NC]
重写规则 ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
到目前为止运行良好。唯一的缺点:
它还将 "multiple-trailing-slash"-URLs 转发到 non-trailing-slash-URLs。
示例:http://example.tld/foo/bar////// 转发到http://example.tld/foo/bar
而我只希望http://example.tld/foo/bar/ 转发到http://example.tld/foo/bar。
那么,如果它实际上是一个尾斜杠,是否可以只消除尾斜杠?
对不起,如果这是一个有点烦人或奇怪的问题!
谢谢。
【问题讨论】:
-
为什么又问同样的问题? stackoverflow.com/questions/3068091/…
标签: apache .htaccess mod-rewrite redirect rewrite