skip to Main Content

Assuming we have a page with random seo friendly url like /some/page.html
How to describe rules for urlManager in config that specifies condition in where if standard rote (e.g. SomeController with actionPage) does not exitsts than performs the specified default route (e.g. DefaultController / actionDefault)?

This rule overrides default route and forwards all requests to my specified route

'urlManager' => [
        ...
        'suffix' => '.html',
        'rules'=>[
            '<alias:[0-9a-zA-Z-_/]+>' => 'default/default',
        ]
]

In other words, algorithm should be as following:

  1. Check if the parsed url have matched with existing module/controller/action then handle this one
  2. Otherwice handle the request by the route predefined in config

2

Answers


  1. Chosen as BEST ANSWER

    I guessed the deal is not in routing. My problem was solved by extend urlManager class with override parseUrl method which checks for each request for existence of its url in DB. If is not present then returns parent method result. Thanks for attempt to help :)

    P.S. But if this url is coincident with standard routing scheme then overrides this one.


  2. Here is a good manual on urlManager: guide yii2

    Also you have to change .htaccess on server for mod_rewrite (Apache or Nginx) => guide yii2

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search