mir13
mir13

Reputation: 1

301 Redirects and non-www to www Canonical Problems (Yii Framework)

The 301 redirection of non-www to www doesn't work completely on my site (CMS: Yii Framework). Here's my htaccess:

IndexIgnore */*
RewriteEngine on

#if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

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

It's ok when I type example.com, the redirection points to www.example.com but when I type "example.com/tag/world" the redirection doesn't work. I don't know why. :/

And when I type example.com/news (category) I don't get the redirection to www.example.com/news, the URL redirects to example.com/index.php/.

In the urlManager section of the file main.php you can see below the code for the tag and the category:

'tag/<titre>'=>'frontend/categorie/tag',
'chroniqueur/<titre>'=>'frontend/categorie/liste',
'<titre>'=>array('frontend/categorie/index', 'urlSuffix'=>'/'),
'search/<titre>'=>'frontend/search/index',

Do I have to modify or change something ? I'm new on Yii.

Upvotes: 0

Views: 376

Answers (1)

anubhava
anubhava

Reputation: 785246

Move 301 rule before other rule:

IndexIgnore */*
RewriteEngine on

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

#if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

Upvotes: 1

Related Questions