我使用mod_rewrite/.htaccess获得漂亮的URL。mod_rewrite:删除尾部斜杠(只有一个!)
我使用这个条件/规则来消除尾随斜杠(或者说:通过301重定向重写到非尾随斜杠URL;我这样做是为了避免重复的内容,因为我喜欢URL没有后斜线更好):
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{HTTP_HOST} !^\.localhost$ [NC] RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
到目前为止工作得很好。唯一缺点:
它也转发“多行尾斜杠”-URL到非尾随斜杠-URL。
例子:
http://example.tld/foo/bar//////
转发到http://example.tld/foo/bar
而我只想http://example.tld/foo/bar/
转发到http://example.tld/foo/bar
。
那么,如果实际上只有一个只有一个尾部斜线,是否可以只消除尾部的斜线?
对不起,如果这是一个有点烦人或奇怪的问题!
谢谢。
同样的问题:http://stackoverflow.com/questions/19990838/remove-trailing-slash-from-sub-directory-folder-apache-1-3-42-directoryslash-off – 2016-07-06 16:54:49