通过htaccess删除尾部斜杠

时间:2014-04-01 07:05:19

标签: .htaccess trailing-slash duplicate-content

根据谷歌的建议,我尝试在我的.htaccess中添加一些代码以防止重复内容。 这是我的代码:

#Duplicate Content
RewriteCond %{HTTP_HOST} !^www.soomar63.com$ [NC]
RewriteRule ^(.*)$ http://www.soomar63.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ 
RewriteRule ^index\.php$ http://www.soomar63.com/ [R=301,L]
#Remove Trailing Slash
RewriteCond %{HTTP_HOST} ^(www.)?soomar63\.com$ [NC]
RewriteCond %{THE_REQUEST} !administrator/(.*)$
RewriteRule ^(.*)/$ http://www.soomar63.com/$1 [R=301,L]

这段代码工作正常,只是有点问题:

此代码更正了以下链接:

soomar63.com -> www.soomar63.com
soomar63.com/ -> www.soomar63.com
soomar63.com/index.php/ -> www.soomar63.com
soomar63.com/about.html/ -> www.soomar63.com/about.html

但它没有纠正以下链接:

soomar63.com/index.php?mylink/ -> must correct to www.soomar63.com/index.php?mylink
soomar63.com/about.html#mylink/ -> must correct to www.soomar63.com/about.html#mylink

请帮忙。 谢谢。

1 个答案:

答案 0 :(得分:0)

将以下#Remove Trailing Slash规则替换为

#Remove Trailing Slash

RewriteCond %{HTTP_HOST} ^(www.)?soomar63\.com$ [NC]
RewriteCond %{THE_REQUEST} !^/?administrator$
RewriteRule ^ http://www.soomar63.com%{REQUEST_URI} [R=301,L,QSA]