I
I
Ipsum2013-12-24 16:41:41
Yii
Ipsum, 2013-12-24 16:41:41

Rule for urlManager

There are aliases - categories of goods (for example, food, shoes), as well as aliases of information pages (about, contact).
From rules

'rules' => [
          ...
        '<alias:.+>' => 'catalog/sectionByAlias',
        '<page:.+>' => 'page/PageByAlias'
    ],

According to this scheme, only the first rule site.ru/food will work, and site.ru/contact will return "category not found", you can redirect to page/PageByAlias ​​in catalog/sectionByAlias ​​if this category is not found, but there are probably others way. Which?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Kupreichik, 2013-12-24
@Ipsum

<alias:.+>and <page:.+>are the same url. <page:.+>will never work, because The 1st satisfying condition will be <alias:.+>. The rules can be clarified and changed in places:

'<page:(about|contact)>' => 'page/<page>',
'<alias:\w+>' => 'catalog/<alias>'

If I were you, I'd leave it better /catalog/categoryname. Such urls are more readable and understandable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question