没有查询字符串的重定向主页

时间:2012-12-25 20:22:38

标签: .htaccess redirect query-string

我正在使用joomla,我需要在htaccess中添加一个很好的重定向。

我需要重定向所有这些:

mysite.com to www.mysite.com  
mysite.com/index.php to www.mysite.com  
www.mysite.com/index.php  
www.mysite.com/    to www.mysite.com  
www.mysite.com/?    to www.mysite.com  
www.mysite.com/?tp=1   to www.mysite.com  
www.mysite.com/?t    to www.mysite.com  
www.mysite.com/?tp  or anything else after ?   to www.mysite.com  

在我的htaccess中我只有这个:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite.com$
RewriteRule ^(.*) http://www.mysite.com/$1 [QSA,L,R=301]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.mysite.com/ [R=301,L]

2 个答案:

答案 0 :(得分:0)

RewriteCond %{QUERY_STRING} !^$
RewriteRule ^$ http://www.mysite.com/ [R=301,L]

答案 1 :(得分:0)

而不是:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.mysite.com/ [R=301,L]

试试这个:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/index\.php$ 
RewriteRule .*  /? [L,R=301]

RewriteCond %{QUERY_STRING} .
RewriteRule .*  /? [L,R=301]

<强>已更新

请用以下内容替换所有规则:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite.com$
RewriteRule ^(.*) http://www.mysite.com/$1 [QSA,L,R=301]

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/index\.php$ 
RewriteRule .*  /? [L,R=301]

RewriteBase /
RewriteCond %{QUERY_STRING} .
RewriteRule .*  /? [L,R=301]

它将删除index.php和所有查询。