Urlmanager With Nginx

I have read through the documentation and forum posts on how to set-up urlManager and configure Nginx to match but must be missing something because I just can’t get it to work.

I would like to make the default URL (how I see it now) of http://domain.com/site/page?view=about to work as http://domain/about

My current urlManager config looks like the following:




   'urlManager'=>array(

      'urlFormat'=>'path',

      'showScriptName'=>false,

      'rules'=>array(

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

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

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

         'about'=>'site/about',

      ),

   ),



I’m just really confused as there seems to be many varying ways that I can find but none of them are working for me. Can anyone offer some advice?

Nginx (version 1.1.19) config:




location / {  # running in root of virtual host

    try_files $uri $uri/ /index.php?r=$request_uri;

}


location ~ \.php {      

    fastcgi_pass  127.0.0.1:9000;

    fastcgi_index index.php;

    include fastcgi_params;

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    fastcgi_param PATH_INFO $fastcgi_script_name;

    access_log off;

}



No one?

Maybe this?




   'urlManager'=>array(

      'urlFormat'=>'path',

      'showScriptName'=>false,

      'rules'=>array(

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

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

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

         '<view:about>'=>'site/page',

      ),

   ),



Not tested.

Thanks for the reply but I get a 404 error with that. I’ve tried every combination I can find but none are working for me.

try:


/index.php/$request_uri

Thanks again but this also returns a 404 error.

Is the 404 error thrown by nginx or by Yii?

if by nginx try to check in logs what it gets

if by Yii - what is the full error (there should by info about controller/action requested that was not found)

also - if nginx throws this error - it means that index.php does not even get called, so you should look at your rewrite rules (and problem is almost for sure there)

The error is being thrown by Yii. The error message when trying to load http://domain/about is




The system is unable to find the requested action "about".



I understand that my rules (either Nginx of urlManager config) are incorrect but every combination I’ve found and tried have not worked. I’m at a loss of what to try next.

It means that ‘http://domain.com/about’ should be routed to SiteController’s actionAbout method.

When you don’t have that action in that controller, the rule above will fail.

If you are using CActionView for your ‘about’ page, the route should be SiteController’s ‘page’ action, with the ‘view’ parameter set to ‘about’.




         '<view:about>'=>'site/page',



I have it it working now. It started working after removing the three rules that Yii generates itself.




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

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

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



I have the same, removing rules also did not work… It works if I put showScriptName=true