I have the following url:
If I input the url in the browser, it matches de rule:
'<module:user>/<slug:[\w\-]+>' => '<module>/<slug>'
If I create the url:
Yii::$app->urlManager->createAbsoluteUrl(["user/index", "slug" => "login"]);
It should create the same url as above but instead it creates:
http://example.com/user/index?slug=login
But If I change the rule to:
'<module:user>/<slug:[\w\-]+>' => '<module>/index'
It works ok, any ideas why? I guess for some reason:
- It is passing slug empty to or
- It is an invalid value.
Any ideas?
That is because
slugis part of the route pattern:'<module>/<slug>'. So<slug:[\w\-]+>is not treated as a named GET param, but as a part of the route. That means that URL/user/somethingwill point to routeuser/somethingwithout any GET params.You should not use the same name for route patterns and named params. You should either use different name:
Or hardcode action for specified rule (as you already did in second example):
Note that this will also match standard actions, like
user/view.