Adding new rules in url manager and keep old links working

Hello all,

I am currently having an issue with the URL manager. I added new rules but all the old links (before the rules) do not work anymore and redirect to the home page.

Is there a way to keep previous links active?

Here is my urlManager configuration:




            'urlSuffix' => '.html',


                'evenement/<url>' => 'site/event',

                'agenda' => 'agenda/index',

                'login' => 'site/login',



And my .htaccess:

Options +FollowSymLinks

IndexIgnore */*

RewriteEngine on

# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php

RewriteRule . index.php

For example I used to have:

But the latter doesnt work anymore once I added my rules.

Do you have any idea why?

Many thanks.

Hum I am a bit surprised that no one had this issue before?

I am guessing that this is some URL rewriting magic, but I am really lacking of knowledge in that area :confused:

You configured urlManager to use path format (site/controller/action/param/value) and index.php hiding, but your old url’s are in get format (site/index.php?r=controller/action&param=value). You should still be able to explicitly include index.php when accessing the site, but the path format will pose a problem. To the best of my knowledge you’ll have to set urlFormat=‘get’.


There is no ways to use both system, so if you change from path to url you will lose lot of score for SEO.

Check FlexicaCMS url manager.

hum I was thinking of modifying the htaccess and add a new condition:

RewriteCond %{REQUEST_URI} /index.php

RewriteRule ^/index.php\?r=site/(.*) /$1

Does not work, but I am guessing the syntax is not correct yet I will find it :)

What do you think?

OK so finally, decided to add a new check in the bootstrap directly (index.php). So basically added a switch for the GET variable r and redirect to the new URL rules

if ($_GET['r']) {

    switch ($_GET['r']) {

        case 'site/blabla':

            $url = 'blabla';




header("Location: $url");


Sounds a bit dodgy but could not find an alternative :)

nice idea, I will keep in mind for future.

Thank for sharing

I took your solution a step further and did the following:

$app = Yii::createWebApplication($env->configWeb); //store the app 

//Change the UrlFormat for urlManager to get if a get request is given instead of a path format one.

if (isset($_GET['r'])) {



$app->run(); //run the app

Everything works perfectly now. Especially connecting with API’s where callback urls are usually in get format. I may also use my path formats for url rewritting. In a way it helps us use both get and path.

However…i feel it is not a long term solution and I will probably some day encounter a wicked bug lol.

Hope it helps someone. It worked for us =)