添加尾部斜杠并删除.htaccess

时间:2013-04-01 12:31:10

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

我怎样才能做到这样的事情: website.com/store/重定向到website.com/store website.com/outbound/store/5重定向到website.com/outbound/store/5 /

我想要的是为没有前缀的网址删除尾部斜杠以及那些带有前缀的网址添加尾部斜杠

我的.htaccess:

Options +FollowSymLinks
RewriteEngine on

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^pa/?$ /admin/index.php [L,QSA] 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ stores.php?store=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^outbound/([^/]*)/([^/]*)$ /outbound.php?type=$1&id=$2 [L]

1 个答案:

答案 0 :(得分:1)

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

# force tailing slash for all urls starting with /outbound/
RewriteRule ^outbound/.*[^/]$ /$0/ [R=301,L]

#remove tailing slash for all except urls starting with /outbound/
RewriteCond $1 !^outbound/
RewriteRule ^(.+)/$ /$1 [R=301,L]

RewriteRule ^pa/?$ /admin/index.php [L,QSA] 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^outbound/([^/]*)/([^/]*)/$ /outbound.php?type=$1&id=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ stores.php?store=$1 [L]

我也清理了一下。