重定向到trailng斜杠(htaccess)

时间:2016-02-29 19:41:51

标签: php apache .htaccess redirect mod-rewrite

尝试为每个链接添加尾部斜杠。例如:

http://testsite.com/products 

301 redirect应该:

http://testsite.com/products/ 

等。但是怎么样?这是我目前的.htaccess

AddDefaultCharset utf-8
Options -Indexes

RewriteEngine On
RewriteBase /
RewriteRule ^.htaccess$ - [F]

RewriteCond %{REQUEST_URI} !\.(ico|css|js|txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !^/admin
RewriteCond %{REQUEST_FILENAME} !^/migrate
RewriteCond %{REQUEST_FILENAME} !^/install
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /index.php [L]

1 个答案:

答案 0 :(得分:0)

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