evstevemd
(Stefano Mtangoo)
1
I have this URL Manager rule
'<module:blog>/<controller:\w+>/<blog:\w+>'=>'<module>/<controller>/index',
Which rewrites my URLs to something like
http://localhost/yii2/web/blog/post/hosanna
blog being module, post is controller and hosanna is GET parameter (called blog)
Now I want to get rid of post in URL and have something like
http://localhost/yii2/web/blog/hosanna
which is much better for me but I have no idea how do I do it!
Any help is appreciated!
Vojtech
(Vojtech Horak)
2
You can leave out the name of the controller from the URL and specify it in the route:
'<module:blog>/<blog:\w+>'=>'<module>/post/index',
In case this rule applies only to the Blog module it can also look like this:
'blog/<blog:\w+>'=>'blog/post/index',
I’d just consider renaming the “blog” parameter to something more apt (e.g. “name”, “slug”, …).
evstevemd
(Stefano Mtangoo)
3
That was it! Thanks a lot!
as per that naming, I find it comfortable to do that way!