htaccess删除尾部斜杠

时间:2014-09-02 20:39:52

标签: .htaccess mod-rewrite redirect trailing-slash

我有以下htaccess: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ index.php [QSA,NC,L] 一切都很好。但是现在我需要从url中删除尾部斜杠。这意味着http://localhost:8888/folder_app/en/psssses/index/asd/(注意尾部斜杠)将重定向到http://localhost:8888/folder_app/en/psssses/index/asd而不会尾随斜杠... 非常感谢您的帮助

1 个答案:

答案 0 :(得分:1)

您可以为此使用新规则:

RewriteEngine On
RewriteBase /folder_app/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} /(.+?)/+[?\s]
RewriteRule ^(.+?)/$ $1 [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]