Can we display url in the format controller/action/id
to /id
in Yii? Also, one major problem is that I need to do this only on the specific controller/action.
For Instance: If I have /user/post/ujjwal
then I need to show /ujjwal
only. And when I have /image/display/ujjwal
then it can be as it is?
I have read the url management in Yii and understand whatever is shown in there. But I dont' know how to control the url based on the controller/action
.
Any help would be appreciated.
Thanks, Ujjwal
What you want can be done, with a few side effects however. If you put this in your
config/main.php
:Put all your more specific rules first, then everything else that is a single unit will go to
/user/post/something
.In my opinion you can not map one customized URL to two or more URL path or action. Like when someone access
/my_username
the will be redirected to/user/post/ujjwal
or/image/display/ujjwal
. The application will be confused because of this pattern/rules.So I recommend you to change the
/image/display/ujjwal
to another pattern/rules. Like/my_username/image
I use
username
as the query string for selected username.Someone has asked this similar question before: How to specify a SEO friendly url like twitter www.twitter.com/<name> using YII framework
In your
config/main.php
try