将index.php重定向到root,使用rewrite_mod将www重定向到非www

时间:2013-05-22 20:53:44

标签: .htaccess mod-rewrite url-rewriting

有人知道如何重定向.htaccess这个规则如下?

http://www.domain.com/index.php to http://domain.com

http://www.domain.com to http://domain.com 
很多坦克

1 个答案:

答案 0 :(得分:13)

由于我猜测index.php是您转到文档根目录时所提供的内容,因此您希望明确检查/index.php请求的内容,以及不是URI的一部分,一旦URL文件映射管道完成它就会成为它。

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]

然后将www转为非www:

RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
相关问题