URL hide controler: several controllers

Hi Yii Comunity,

On my prject, there are 3 controlers:

index.php/client/ACTION for clientController

index.php/seller/ACTION for sellerController

index.php/site/ACTION for siteController (for static pages with no log-in)

I need to hide the siteController to have SEO-friendly URLs for the static pages but to keep the controller name for clientController and sellerController

Example 1

I have:

www.example.com/index.php/site/page?view=about

I need to display the URL:

www.example.com/about.html

Example 2

I have:

www.example.com/index.php/client/register

I need to display the URL:

www.example.com/client/register

I have found a post about hidding controller and index.php but it works for sites with only one controller.

http://www.yiiframework.com/forum/index.php/topic/27985-url-without-controller-name/

Does anyone know how to handle this ?

You either hardcode all those URLs in your config file or you create your own URL manager to handle all this routing.

one possible solution is to list every possible combination of all 3 controllers/actions and define custom rewrite for each case. This has the negative effect of having a lot of rules and having to amend rules each time you add/remove actions.

The other possibility is to extend the curlmanager and write custom conditions.

Hopefully some else can add something to the above

Thanks Roman Solomatin.

I have tried:

‘rules’ => array(

            'about.html' => 'index.php/site/view?=about',


        ),

But it doesn’t work.

Can I ask an example for hardcoding ?

try something like:




'<_c:(client|seller)>/<_a:(create|update|delete)>' => '<_c>/<_a>',

'<_c:(site)>/<_a:(create|update|delete)>' => '<_a>',



not tested. for more info go to http://www.yiiframework.com/doc/guide/1.1/en/topics.url

Does


'rules' => array(

                'about.html' => 'site/view/page/about',

            ),

work?

No, it doesn’t. My exact code is:

‘urlManager’ => array(

        'urlFormat' =&gt; 'path',


        'urlSuffix' =&gt; '.html',


        'rules' =&gt; array(


            'about.html' =&gt; 'site/page/about'

)

is what I suggested not working at all?

I chose to hard-code the actions in config urlmanager. Here’s what worked for me:


'<action:(login|logout|about|auth)>' => 'site/<action>',

Just list all your actions in SiteController here.

The following works as ElMaros expected.

The only shortcoming is that I am not able to conceal the index.php.

I never succeeded on that.




'urlManager'=>array(

			'urlFormat'=>'path',

			'urlSuffix' => '.html',

			'showScriptName'=>true,

			'rules'=>array(

				'<view:\w+>'=>'site/page',

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

			),

		),



You should set showScriptName to [color="#000080"]false[/color]. See: http://www.yiiframework.com/doc/api/1.1/CUrlManager#showScriptName-detail

Dear bennouna

Of course I know that.

The problem is that it works well when urlFormat is set to get.But of course all the url rules are neglected.

When urlFormat is changed to path. It throws the error.

Then I am forced to set the showScriptName to true.

All these observations are based my experience in my localhost.(Apache/2.2.22 (Ubuntu) Server at localhost Port 80)

My .htaccess file




Options +FollowSymLinks

IndexIgnore */*

<IfModule mod_rewrite.c>

RewriteEngine on


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

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule ^.*$ /index.php [L]

</IfModule>




Regards.