3

有人知道我如何在下面的 .htaccess 中重定向此规则?

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

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

许多坦克

4

1 回答 1

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]
于 2013-05-22T21:04:18.510 回答