I set to the main config the following url rules:
'urlManager'=>array( 'urlFormat'=>'path', 'showScriptName'=>false, 'rules'=>array( '<controller:\w+>'=>'<controller>/list', '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', '<controller:\w+>/<id:\d+>/<title>'=>'<controller>/view', '<controller:\w+>/<id:\d+>'=>'<controller>/view', '\?r=<controller:\w+>/<action:\w+>' => '<controller>/<action>' ), ),
Everything is woking fine, but I also want the previous url format to keep working so I don't have to rewrite lots of urls that I don't care it to be seo-friendly:
index.php?r=controller/action¶m1=value1
But it shows an error now. Is there a way to keep it working?
To my opinion the best way is to replace all old urls with your IDE regex replace option. But anyway you can do what you want this way:
Use following route rule in the urlManager config:
'rules' => [ [ 'class' => 'my\namespace\UrlRule', 'pattern' => '<controller>/<action>', 'route' => '<controller>/<action>', ], ...
Extend yii\web\UrlRule with your my\namespace\UrlRule and rewrite its 'parseRequest' method so that it could use $_GET['r'] parameter value if is set:
You may also extend yii\web\Request instead so that it's 'getPathInfo' method could use $_GET['r'] parameter if set.