Remove controller name from URLs in Yii2

偶尔善良 提交于 2019-12-11 10:36:09

问题


How can I remove the controller name from URLs in Yii2?

I'm aware of simple aliases, but I'm not sure how to apply aliases to a little bit more complex rule, like the following one:

'rules' => [
    'public/<seo_url:.*?>/<category_id:\d+>/<product_id:\d+>' => 'public/product'
]

This will create a rule so URLs like /product/this-is-a-slug/94/12 will call the actionProduct in my Public controller.

How can I make an alias that would call that same action if I try to access a product using this URL: /this-is-a-slug/94/12 ?


回答1:


Set new rulw on top of all rules. Like that:

'rules' => [
    '<seo_url:.*?>/<category_id:\d+>/<product_id:\d+>' => 'public/product',
]

This is work for me.



来源:https://stackoverflow.com/questions/29577022/remove-controller-name-from-urls-in-yii2

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