I am working with Yii2 and I would like to use urlManager with routing to convert all non-letter and non-character characters to slashes. I examined a lot of questions about what has already been asked ( # 1 , # 2 , # 3 , # 4 ), but no one solved it, because they either show a little similar, but not what I want or not I work for me at all.
I have simple urlManager rules:
//... 'urlManager' => [ 'class' => 'yii\web\UrlManager', 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => array( '<controller:\w+>/<id:\d+>' => '<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', '<controller:\w+>/<action:\w+>' => '<controller>/<action>', ), ],
.htaccess (also simple):
RewriteEngine on
In my case, my ugly URL is ( SiteController -> public function actionTestRouter() ):
local / interface / web / index.php r = Site% 2Ftest-router &? ID = 10 & Token = ADB & Module = P120
With the rules I wrote above, I get a better result (because it removes index.php?r= and converts %2F to / ):
local / interface / web / website / test router ident = 10 &? Marker = ADB & module = P120
What I want to get:
local / interface / web / website / test router / ident / 10 / token / adb / module / P120
My few rules with rules:
'test-route/<ident:\d+>/<token:\w+>/<module:\w+>' => 'test-route' // 1 '<controller:\w+>/<action:\w+>/<ident:\d+>/<token:\w+>/<module:\w+>' => '<controller>/<action>' // 2 '<controller:\w+>/<action:\w+>/<slug:[a-zA-Z0-9_-]+>/' => '<controller>/<action>/<slug>' // 3 (not even sure what slug does here
It would also be nice if the rules are applicable to any parameters and values, regardless of their name and values.