【问题标题】:Redirect index.php to root, and www to non www with rewrite_mod [duplicate]使用 rewrite_mod 将 index.php 重定向到 root,并将 www 重定向到非 www [重复]
【发布时间】:2013-05-18 01:45:17
【问题描述】:

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

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

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

许多坦克

【问题讨论】:

标签: .htaccess mod-rewrite url-rewriting


【解决方案1】:

由于我猜测 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]

【讨论】:

  • 为什么{3,9}后面有空格\ /
  • @ShreenivasChikati 因为这就是请求的第一行,例如:GET /index.php HTTP/1.1
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-18
  • 1970-01-01
  • 2011-01-05
  • 2018-06-06
相关资源
最近更新 更多