我想把如www.example/index.php?r=site/index?id=49
的地址改写为www.example/site/index/49.html
这样的,现在我成功去掉了index.php和r=字符,url变成了www.example/site/index?id=49
,就卡在urlManager的rules这里,请问我该怎么写rules?
另外,我要是想重写为www.example/site/49
该怎么写rules呢,求大神给下指点。
另外,yii2的重写具体有哪些规则,语法是怎么样的,有资料的给我个地址也行。
不建议改成www.example/site/49
这种形式,最基本的参数site后面的index也省去了。如果是site/create
,也就是在url中create也会被省去。
但如果题主是想将www.example/site/index?id=49
改成www.example/site/index/id/49
的话,不妨参考这个: http://www.cnblogs.com/dcb3688/p/4607968.html
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'suffix' => '.html',
'rules' => [
"jitapu/<artist:\w+>/<id:\d+>" => "jitapu/view",
"<controller:\w+>/<action:\w+>/<id:\d+>" => "<controller>/<action>",
"<controller:\w+>/<action:\w+>" => "<controller>/<action>",
],
],
吉他谱点我网就是采用这种形式的,请看http://www.jitapu.me/jitapu/xuwei/20352.html ,你这种的话只要这一句就可以了
"<controller:\w+>/<action:\w+>/<id:\d+>" => "<controller>/<action>",