这个问题在这里已经有了答案:
Generic htaccess redirect www to non-www
(24 个回答)
8 年前关闭。
有人知道如何在 .htaccess 中重定向此规则?
http://www.domain.com/index.php to http://domain.com
和
http://www.domain.com to http://domain.com
许多坦克
最佳答案
因为我在猜测 index.php
是当您转到文档根目录时得到的服务,您想明确检查 /index.php
是什么要求 ,而不是 URI 的一部分,一旦 URL 文件映射管道完成它的工作,它就会成为 URI 的一部分。
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]
关于.htaccess - 使用 rewrite_mod 将 index.php 重定向到 root,将 www 重定向到非 www,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16701394/