2016-04-22 87 views
1

我正在使用.htaccess規則。.htaccess文件 - 刪除所有URL的尾部斜槓

我想刪除所有網址的尾部斜槓。

 For ex:- 
     http://www.test.com/admin Working fine 
     But 
     http://www.test.com/admin/ Gives me error. 

如果我跑URL像http://www.test.com/admin/dashboard/ 那麼它auomatically重定向到http://www.test.com/admin/dashboard

我在htaccess文件把下面的代碼。

 RewriteCond %{REQUEST_FILENAME} !-f 
     RewriteCond %{REQUEST_URI} !(.*)/$ 
     RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [L,R=301] 

但它的重定向是這樣的。

http://www.test.com/var/www/html/test/public/admin

+0

似乎複製。請檢查http://stackoverflow.com/questions/21417263/htaccess-add-remove-trailing-slash-from-url – sAcH

+0

感謝您的快速響應..它的工作作爲魅力 –

回答

0

原著的答案 - Htaccess: add/remove trailing slash from URL

的正下方RewriteEngine敘述上線,添加:

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)/$ /$1 [L,R=301] 

強制執行無尾隨斜線政策。

爲了執行尾隨斜線政策:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]