defaultRoute does not work
Hi, I have set defaultRoute in my application and enable enableStrictParsing in url Manager component, it seems that they can't work together? If it is true and it isn't a bug, I think, It would be cool to mention that in documentation.
P.S. sorry for my bad English.
Reproduced. With
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
],
defaultRoute is ignored. The same effect could be achieved by explicitly adding the following to rules:
'' => 'site/index', // default route here
@yiisoft/core-developers do you think it should be somehow fixed? If yes, any ideas? If no I think it should be documented in defaultRoute phpdoc.
default route does not have anything to do with UrlManager, if you enable strict parsing you have to give a route for every possible Url. if there is none, no URL will be there.
if you add '' => '' as a rule the default route will apply too so this is nothing to be fixed. Not sure if there is a need to clarify something somewhere.
See this http://www.yiiframework.com/doc-2.0/guide-runtime-routing.html#default-route
@qiangxue ? The issue is about defaultRoute doesn't work when we're using strictParsing in URL manager.
@samdark As explained in the guide, defaultRoute is used when an empty route is resolved from the current request. It has nothing to do with strictParsing.
OK.
@qiangxue @samdark I just think that this behaviour is an undocumented feature, not a bug. May be, it should be mentioned in documentation, that defaultRoute would be ignored, when strictParsing is enabled. I think, it wouldn't be obvious for a new user
@glagola As I said, defaultRoute has nothing to do with strictParsing. Even if you enable strictParsing, defaultRoute may still be used if a rule resolves the request into an empty route.
@qiangxue Thank you! Such application config works perfectly:
[
...
'defaultRoute' => 'site/login',
...
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
...
'rules' => [
...
'' => '', // <- this line should be added
],
],
...
]