Remove controller name from URLs in Yii2

2019-08-07 06:49发布

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 ?

标签: php seo yii2
1条回答
迷人小祖宗
2楼-- · 2019-08-07 07:26

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.

查看更多
登录 后发表回答