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¶m1=value1
but shows error now. there way keep working?
to opinion best way replace old urls ide regex replace option. anyway can want way:
use following route rule in urlmanager config:
'rules' => [ [ 'class' => 'my\namespace\urlrule', 'pattern' => '<controller>/<action>', 'route' => '<controller>/<action>', ], ...
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
Post a Comment