Remove old url from access

I am using advanced app and noticed that when I changed name of the controller using urlManager it is accessible by the old name and it is possible to open with new url name as well.

How can I disable old name and redirect old to new?

Assume that I had:


now I have:


both of them work properly, but I would like to redirect site/<action> to website/<action> permanently

 I changed name of the controller using urlManager

What does your config look like?

'urlManager' => [

    'enablePrettyUrl' => true,

    'showScriptName' => false,

    'rules' => [

        'about' => 'site/about',

        'enter/<action:[\w\-]+>' => 'site/<action>',

        'enter/<action:[\w\-]+>/<id:\d+>' => 'site/<action>',

        'client/<controller:[\w-]+>/<action:[\w\-]+>/<id:\d+>' => '<controller>/<action>',

        'client/<controller:[\w-]+>/<action:[\w\-]+>' => '<controller>/<action>',

        'client/<controller:[\w-]+>' => '<controller>/index',

        'client/<controller:[\w-]+>' => '<controller>',



Is .htaccess an option?

Not sure if this is the best practice. Does that mean that whenever I change name of the contoller in urlManager I need to do it in .htaccess as well?

Let’s say you start with a controller named SiteController. It’ll serve all requests to “site/…”.

Now you add a rule to your UrlManager that maps all calls to "website/…" to SiteController. Yii will still find the controller for "site/…" requests, meaning both "site/…" and "website/…" work. This is your current status, from what I understand.

.htaccess (or httpd config) allows you to redirect (301) all requests from “site/…” to “website/…”. Yii isn’t involved in this redirect and it’s a fast and simple solution.

If you change the name of your Controller from SiteController to NewSiteController, you won’t have to touch .htaccess, only UrlManager.

If you decide to abandon "website/…" and redirect it to "mynewurl/…", you have to add an entry to .htaccess.

Alright, it seems to be a good solution. I will try and let you know if it has worked.

Isn’t there a config option for defaultController?