1

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 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah, that will work, but that way I'll have to create 2 rules for each URL. Not that I pretend having 10000 different rules, but still, it doesn't look like the cleanest solution.
Please, take me examples.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.