php - Yii User-friendly url and keep the old get format working -


i set main config 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 woking fine, want previous url format keep working don't have rewrite lots of urls don't care seo-friendly:

index.php?r=controller/action&param1=value1 

but shows error now. there way keep working?

to opinion best way replace old urls ide regex replace option. anyway can want way:

  1. use following route rule in urlmanager config: 'rules' => [ [ 'class' => 'my\namespace\urlrule', 'pattern' => '<controller>/<action>', 'route' => '<controller>/<action>', ], ...

  2. extend yii\web\urlrule my\namespace\urlrule , rewrite 'parserequest' method use $_get['r'] parameter value if set:

     namespace my\namespace;      class urlrule extends \yii\web\urlrule     {         public function parserequest($manager, $request)         {             if ($pathinfo = \yii::$app->request->get('r')) {                 \yii::$app->request->setpathinfo($pathinfo);             }             return parent::parserequest($manager, $request);         }     } 

you may extend yii\web\request instead it's 'getpathinfo' method use $_get['r'] parameter if set.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -