Reputation: 329
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
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