将www重定向到非www并删除index.php

时间:2015-03-18 16:12:20

标签: apache .htaccess redirect

我设置了一个路由器,使用以下内容重写/index.php/this/that到/ this / that:

RewriteRule ^$ index.php [QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

我怎样才能将www重定向到非www?我尝试过以下各种变化,但还没有成功:

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

谢谢!

1 个答案:

答案 0 :(得分:2)

只需在其他规则之前放置www删除代码:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]

RewriteRule ^$ index.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
相关问题