1

My present URL structure is as below:

http://www.mydomain.com/module/controller/action

I need to hide the module section of the URL. Is there any way this can be done?

Thanks.

2 Answers 2

4

To point the URL http://www.mydomain.com/customer/login to the module, in you config (protected/config/main.php) under urlManager:

'urlManager'=>array(
        'urlFormat'=>'path',
        'showScriptName' => false,
        'rules'=>array(
            'customer/login' => 'module/controller/action',

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

To make any controller action go to module/controller/action (as discussed below) you can use:

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

or

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

Depending on whether the controller/action part of the value (on the right hand side of the =>) is a set value, or a variable.

So if you want any controller/action to go to the exact url module/controller/action, you would use the first example. For example if you want the controller/action site/test to go to module/controller/action, you would use the first example above

If you want any controller/action to go to a dynamic controller/action you use the second. For example, if you want the controller/action site/test to go to module/site/test, you would use the second example above

This new rule must be above the 3 default Yii rules as they are read and top to bottom and match the first rule it finds only

Sign up to request clarification or add additional context in comments.

7 Comments

Not sure why .. but this is still not working I am getting a 404 error still
Strange... I have updated my answer. Do you have showScriptName set to false?
Ok.. that worked ..thanks. Now is there a way I can get any controller/action to go to module/controller/action ?
Great, no problem. Check my edit to see how to make any controller action go to module/controller/action
Can you tell me how to hide my module name from url iam not able to do this using this code i mam using Yii Framework 1.1.x
|
1

Yes, you can define any url rules in your config.

Your url rule may look something like this:

'<controller:(foo|bar)>/<action>' => 'module/<controller>/<action>',

2 Comments

I want /customer/login to be processed by /module/customer/login This is not happening with the above.
'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>', '<controller:(customer)>/<action>' => 'customer/<controller>/<action>' ), Can you please correct the above?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.