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:
- Check if the parsed url have matched with existing module/controller/action then handle this one
- Otherwice handle the request by the route predefined in config
2
Answers
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.
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