Profile URL

What are the rules for rewriting all urls to a controller/action? I am trying


‘<profile>’ => ‘site/users/show?id=<profile>’,

I want something like to redirect to the users/show action, passing a get var from the end of the url. Thanks.

Try this:





I’m assuming you’ve got a controller named UsersController with a method UsersController.actionShow($profile). It won’t work otherwise.

Thanks, but is that a valid regular expression? Yii is saying it isn’t,

Similar to the Yii’s default rules:




'<controller:\w+>/<id:\d+>'  => '<controller>/view',



In your case, you could try:

'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',

Thanks. I tried:

'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',


'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',


'/<id:\d+>' => 'user/show',

With no luck. That last one is what I think is most representative of what I’m trying to do, which is to redirect to the user/show action and pass the id via GET. The equivalent name should be something like but I’m just trying to shorten it to

I’m building a really user heavy site, and we need to shorten up the url to something like or

I added the rewrite rules to remove index.php. Here is my .htaccess:

RewriteEngine on

#RedirectMatch (.*)admin\.php$ $1backend.php

#RedirectMatch (.*)admin$ $1backend.php

#RedirectMatch (.*)admin/$ $1backend.php

# if a directory or a file exists, use it directly

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

#otherwise forward it to index.php

RewriteRule . index.php

<IfModule mod_headers.c>

 <FilesMatch "\.(swf|gif|jpg|png|ico|cur|css|js)$">

  Header set Cache-Control "max-age=604800"



<IfModule mod_expires.c>

 ExpiresActive On

 ExpiresDefault A604800

 ExpiresByType application/x-shockwave-flash A604800

 ExpiresByType image/gif A604800

 ExpiresByType image/jpeg A604800

 ExpiresByType image/png A604800

 ExpiresByType image/x-icon A604800

 ExpiresByType image/x-win-bitmap A604800

 ExpiresByType text/css A604800

 ExpiresByType text/javascript A604800


RewriteEngine on


Ganh. For real? It certainly is: It should match all characters except the backslash. Try \w+ instead.

If I got you right,

you are trying to redirect to

In this case, UserController and actionShow is considered.

If the data of profileName comes from db, you may have to get it manually from model, (but if it stores in Session then it can be used directly) and place it directly in the rule as a php variable which has its proper profileName value.

Then it should be:

'<controller:\w+>/<action:\w+>/<id:\d+>/<profile:\w+>' =>'/'.$profileName,

If the profileName has value then it should work. Just try it but i am not sure.

Hope that helps :)

To give everyone an update, all methods throw a 404 error inside the Yii template when you try The homepage works on / and actions work on controller/action url.

I am going to try to use straight .htaccess. Would I have to change the config file to show index.php again and rewrite the .htaccess rules to redirect everything to index.php?r=user/show&id=profileName? Thanks.

This worked for me: