使用.htaccess删除尾部斜杠

时间:2012-09-21 09:03:54

标签: apache .htaccess

我在这里遇到了不同的解决方案,但由于某些原因它对我不起作用,我发现删除尾部斜杠的解决方案是

# remove trailing slashes
RewriteRule (.*)/$ $1 [L,R=301]

但它对我不起作用,下面是我的.htaccess代码:

Options -Multiviews
Options +FollowSymLinks

RewriteEngine on
RewriteBase /

RewriteRule ^([^/]+)/$ index.php?slug=$1
RewriteRule ^([^/]+)/([^/]+)$ index.php?slug=$1&post=$2

<IfModule mod_php5.c>
php_flag magic_quotes_gpc Off
</IfModule>

请让我知道如何修复,以便http://domain.com/about/代替http://domain.com/about

问候

1 个答案:

答案 0 :(得分:0)

你的第一条规则是使用尾部斜杠:

RewriteRule ^([^/]+)/$ index.php?slug=$1

尝试在你的htaccess中使用它:

Options -Multiviews
Options +FollowSymLinks

RewriteEngine on
RewriteBase /

RewriteRule ^(.*)/$ $1 [L,R=301]

RewriteRule ^([^/]+)$ index.php?slug=$1 [L]

RewriteRule ^([^/]+)/([^/]+)$ index.php?slug=$1&post=$2 [L]

<IfModule mod_php5.c>
   php_flag magic_quotes_gpc Off
</IfModule>
相关问题