.htaccess 重定向没有查询字符串的主页
我正在使用joomla,我需要在我的htaccess中设置一个良好的重定向 我需要重新定向所有这些:.htaccess 重定向没有查询字符串的主页,.htaccess,redirect,query-string,.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
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]
与此相反:
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和所有查询。Ty要获得帮助,但它不起作用,我复制了代码,但尝试重定向www.mysite.com/?它给了我一个错误我试过了,但当我尝试访问我的网站时,它给了我一个错误,这个错误:Firefox检测到服务器正在以一种永远不会完成的方式重定向对此地址的请求。@NiceOne可能会进入一个循环。更新了我的答案。Ty更新了你的答案,但它不起作用,它将我所有的网站页面重定向到主页,我四处查看,看看用joomla创建的其他网站是否也有同样的问题,也许用joomla不可能做到这一点重定向我让joomla sef enabledI尝试了这一点,它只适用于?tp=1 RewriteCond%{QUERY_STRING}tp=.*RewriteRule^.*$index.php[F,L]我在一台真正的服务器上测试了答案中的规则集,并按预期工作。当你在你的电脑上测试它们时,你无法找出问题所在。存在index.php时是否已删除??查询出现时是否已删除?将来,如果您有Joomla问题,请将其发布到Joomla Stack Exchange。你设法解决了这个问题吗?此页面似乎已被放弃。
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]