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

标签 .htaccess mod-rewrite url-rewriting

这个问题在这里已经有了答案:





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/

相关文章:

php - 如何防止一个文件被 .htaccess 重定向?

php - 重定向而不改变url

php - Codeigniter Htaccess 和 URL 重定向问题

java - Spring 3.2 mvc,如何在 Controller 内重写 url 作为重定向 View 的一部分,并发送永久状态代码

php - URL_TITLE() 代码点火器

WordPress 403 禁止错误

arrays - Htaccess : multiple parameters and nested parentheses

mod-rewrite - 两部分 SEO 友好 URL

php - 删除带有 mod_rewrite 和 SEO 问题的 .php 扩展名

javascript - 删除 URL 中的哈希值 (fullpage.js)