在Yii Framework中从www重定向到非www

时间:2014-10-16 19:12:57

标签: apache .htaccess mod-rewrite redirect yii

如何正确地从www重定向到非www url?
我用这句话:

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

但它们效果不佳。他们将andex.php添加到地址并删除第一个由/ /.

舍入的exp

http://www.payamkadeh.com/profile/show/behtateam - > http://payamkadeh.com/index.php/show/behtateam

我的完整htaccess:

RewriteEngine On
Options +FollowSymlinks
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

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

1 个答案:

答案 0 :(得分:3)

在内部路由之前有www重定向规则:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /

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

RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
相关问题