Native Url and PrettyUrl run both at the same time


Does exist an easy way to run old and new urls after enable prettyUrl in configuration ?

'urlManager' => [

  'enablePrettyUrl' => true,

  'showScriptName' => false,

   'rules' => [

                'gallery/<uid:id+>' => 'gallery/default/index',


For example  


But google has alredy indexes the second one, when someone click on google result go to the old url that is now broken (no request found)

Of course after of few days google re indexing by website but I don’t want to lose visits in mean time.

So I want both of new and old url to be valid

How to achieve that ?

I found a solution but it is not best for me

I wonder if it is best way to do that in htaccess directly like that

Is there a yii-way to do that bi-directional ?


I believe that may be a bug. You would have to clarify with an admin on Github, but after looking at the parseRequest function in the URLManager class, the code should fallback to traditional route parsing if a pretty url route does not match, which it doesn’t.

As a quick fix you could overide the current URLManager and replace the parseRequest function with this:

public function parseRequest($request)


        if ($this->enablePrettyUrl) {

            /* @var $rule UrlRule */

            foreach ($this->rules as $rule) {

                if (($result = $rule->parseRequest($this, $request)) !== false) {

                    return $result;



            if ($this->enableStrictParsing) {

                return false;



        Yii::trace('Pretty URL not enabled. Using default URL parsing logic.', __METHOD__);

        $route = $request->getQueryParam($this->routeParam, '');

        if (is_array($route)) {

            $route = '';


        return [(string)$route, []];


I think I had the same issue in Yii 1.x

I just open an issue on github