Saleh Hashemi
Saleh Hashemi

Reputation: 329

redirect from www to non www in Yii Framework

How can I redirect from www to non www url properly?
I use this lines:

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

but they don't work well. they added andex.php to the address and remove the first exp rounded by / /.

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

My full 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

Upvotes: 1

Views: 639

Answers (1)

anubhava
anubhava

Reputation: 785246

Have www redirect rule before internal routing one:

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]

Upvotes: 4

Related Questions