Yii basic url rewrite

ⅰ亾dé卋堺 提交于 2019-11-29 16:43:54

These two:

'journey/invite' => 'site/invite',
'journey/linkedin' => 'site/linkedin'

are not working because the url is being matched by a previous rule:

'<controller:\w+>/<action:\w+>'=>'<controller>/<action>'

To prevent that from happening just make sure that rule is mentioned last, before any specific(i.e not matched by regular expressions) rewrites, so your rules can look somewhat like this :

'journey/invite' => 'site/invite',
'journey/linkedin' => 'site/linkedin',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>'

This : \w+ means match any string with one or more occurrences of any “word” character (a-z 0-9 _) and \d+ means match any string with one or more occurrences of any digits (0-9) . Check out php regex.

Edit

Hadn't read your question thoroughly before, the controller in the rule is simply a name for the matched expression, so you could have had '<contr:\w+>/<act:\w+>'=>'<contr>/<act>'.

Edit2

After reading your edited question with the rules array, afaik you could use ''=>'site/journey' instead of '/'=>'site/journey'.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!