Ilya Vo
Ilya Vo

Reputation: 2309

Yii error when i try remove www prefix

With .htaccess i successfully remove index.php from url. For good SEO practice I need to remove WWW prefix. Combination two Apache rules gives an error.

I type www.site.com, i got site.ru - ok!

I type www.site.com/catalog, i got site.ru - error! its main page.

I type www.site.com/page/some_page, i got site/index.php/some_page - error!

(note: rules 'page/' => 'site/page', 'catalog/' => 'site/catalog/',)


.htaccess

RewriteEngine on
Options +FollowSymLinks


#redirect from WWW
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^/?(.*) http://%1/$1 [L,R=permanent]


#remove index.php from url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

Upvotes: 1

Views: 93

Answers (1)

Wit Wikky
Wit Wikky

Reputation: 1542

Try,

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

In place of

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

Hope it would help.

Upvotes: 1

Related Questions