urlManager https|http .com|.local

Hi. I want to prepare rule for subdomain and get it equal for https|http и and for local|remote domain

I started from


'urlManager'=>array(

            'urlFormat'=>'path',

            'showScriptName' => false,

            'rules'=>array(

                "http://subdomain.domain.local"=>'controllerName',

All is OK

After that


'urlManager'=>array(

            'urlFormat'=>'path',

            'showScriptName' => false,

            'rules'=>array(

                "http://subdomain.domain.local"=>'controllerName',

                "http://subdomain.domain.com"=>'controllerName',

                "https://subdomain.domain.local"=>'controllerName',

                "https://subdomain.domain.com"=>'controllerName',



OK

Now i try to get the same result, but it doesn’t work :(


        'urlManager'=>array(

            'urlFormat'=>'path',

            'showScriptName' => false,

            'rules'=>array(

                "<protocol:http|https>://subdomain.domain.<zone:local|com>"=>'controllerName',

 

I guess Yii is determining whether rule is relative or whole url by checking for http:// prefix in rule definition. So your rule breaks this function. try two rules:




"http://subdomain.domain.<zone:local|com>"=>'controllerName',

"https://subdomain.domain.<zone:local|com>"=>'controllerName',



you can also use extended syntax for rule definition and provide defaultParams with ‘protocol’=>‘http’ and so on if you need this param.

Look at code for CUrlRule (CUrlManager.php line 667):


$this->hasHostInfo=!strncasecmp($pattern,'http://',7) || !strncasecmp($pattern,'https://',<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />;

This is I was talking about

Thank you!!!

Now i try to url manage subdomain to module




"http://module.domain.<zone:local|com>"=>'module',

"https://module.domain.<zone:local|com>"=>'module',



Works correctly

But if i only put this




"http://module.domain.<zone:local|com>/<controller:\w+>/<action:\w+>"=>'module',

"https://module.domain.<zone:local|com>/<controller:\w+>/<action:\w+>"=>'module',



It works wrong, works like


=>'site/index',

So




"http://module.domain.<zone:local|com>/<controller:\w+>/<action:\w+>"=>'module/<controller>/<action>',

"https://module.domain.<zone:local|com>/<controller:\w+>/<action:\w+>"=>'module/<controller>/<action>',



doesn’t work to

What is wrong?

this one should work… what is the result? is there any error message? check in application log also…

I’ve solved this problem

redguy, Thanks for your help and attention

It doesn’t work again :(

.htaccess


### Autogenerated directives. Please, DON'T EDIT! ###

### Directives added by user ###


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 ^activate\.php$ /?r=activate [QSA]

RewriteRule . index.php

/config/main.php


                'http://module.domain.<zone:local|com>'=>'module',

                'https://module.domain.<zone:local|com>'=>'module',	

/controllers/SiteController.php


class SiteController extends Controller

{

	public function actionIndex()

	{

        echo "SiteController";

	}

	

	public function actionError()

	{

	    if($error=Yii::app()->errorHandler->error)

	    {

	    	if(Yii::app()->request->isAjaxRequest)

	    		echo $error['message'];

	    	else

	        	$this->render('error', $error);

	    }

	}	

}

/modules/module/controllers/DefaultController.php


class DefaultController extends Controller

{

	public function actionIndex()

	{

		echo "Module DefaultController Index";

	}

}

/modules/module/controllers/SecondController.php


class SecondController extends Controller

{

	public function actionIndex()

	{

		echo "Module SecondController Index";

	}

}

Brows to: http://module.domain.local

Get: Module DefaultController Index

Brows to: http://module.domain.local/second

Get: [color="#FF0000"]Error 404 Unable to resolve the request "second".[/color]

appliacation.log


2012/05/25 12:57:53 [trace] [system.CModule] Loading "log" application component

2012/05/25 12:57:53 [trace] [system.CModule] Loading "request" application component

2012/05/25 12:57:53 [trace] [system.CModule] Loading "urlManager" application component

2012/05/25 12:57:53 [trace] [system.CModule] Loading "coreMessages" application component

2012/05/25 12:57:53 [error] [exception.CHttpException.404] exception 'CHttpException' with message 'Unable to resolve the request "second".' in Y:\home\domain.local\www\framework\web\CWebApplication.php:280

Stack trace:

#0 Y:\home\domain.local\www\framework\web\CWebApplication.php(135): CWebApplication->runController('second')

#1 Y:\home\domain.local\www\framework\base\CApplication.php(162): CWebApplication->processRequest()

#2 Y:\home\domain.local\www\index.php(24): CApplication->run()

#3 {main}

REQUEST_URI=/second

---

2012/05/25 12:57:53 [trace] [system.CModule] Loading "errorHandler" application component

2012/05/25 12:57:53 [trace] [system.CModule] Loading "widgetFactory" application component

2012/05/25 12:57:53 [trace] [system.CModule] Loading "user" application component

2012/05/25 12:57:53 [trace] [system.CModule] Loading "session" application component

2012/05/25 12:57:53 [trace] [system.CModule] Loading "clientScript" application component

OK.

Now let’s change rules

/config/main.php


                'http://module.domain.<zone:local|com>/<controller:\w+>'=>'module/<controller>',

                'https://module.domain.<zone:local|com>/<controller:\w+>'=>'module/<controller>',	

Brows to: http://module.domain.local

Get: [color="#FF0000"]SiteController[/color] without any errors in application.log

Brows to: http://module.domain.local/second

Get: Module SecondController Index.

Let’s change rules again

/config/main.php


                'http://module.domain.<zone:local|com>/<controller:\w+>/<action:\w+>'=>'module/<controller>/<action>',

                'https://module.domain.<zone:local|com>/<controller:\w+>/<action:\w+>'=>'module/<controller>/<action>',	

Brows to: http://module.domain.local

Get: [color="#FF0000"]SiteController[/color] without any errors in application.log

Brows to: http://module.domain.local/second

Get: [color="#FF0000"]Error 404 Unable to resolve the request "second".[/color]

appliacation.log


2012/05/25 12:57:53 [trace] [system.CModule] Loading "log" application component

2012/05/25 12:57:53 [trace] [system.CModule] Loading "request" application component

2012/05/25 12:57:53 [trace] [system.CModule] Loading "urlManager" application component

2012/05/25 12:57:53 [trace] [system.CModule] Loading "coreMessages" application component

2012/05/25 12:57:53 [error] [exception.CHttpException.404] exception 'CHttpException' with message 'Unable to resolve the request "second".' in Y:\home\domain.local\www\framework\web\CWebApplication.php:280

Stack trace:

#0 Y:\home\domain.local\www\framework\web\CWebApplication.php(135): CWebApplication->runController('second')

#1 Y:\home\domain.local\www\framework\base\CApplication.php(162): CWebApplication->processRequest()

#2 Y:\home\domain.local\www\index.php(24): CApplication->run()

#3 {main}

REQUEST_URI=/second

---

2012/05/25 12:57:53 [trace] [system.CModule] Loading "errorHandler" application component

2012/05/25 12:57:53 [trace] [system.CModule] Loading "widgetFactory" application component

2012/05/25 12:57:53 [trace] [system.CModule] Loading "user" application component

2012/05/25 12:57:53 [trace] [system.CModule] Loading "session" application component

2012/05/25 12:57:53 [trace] [system.CModule] Loading "clientScript" application component

So I cant understand, what should I put in rules to get

http(s)://domain.com

http(s)://domain.com/contriller

http(s)://domain.com/contriller/action

http(s)://module.domain.com

http(s)://module.domain.com/contriller

http(s)://module.domain.com/contriller/action

browsable

Please help!

rules must match url in whole or it will not be used. If you want to use default controllers/actions you have to provide rules that match all cases:




'http://module.domain.<zone:local|com>/<controller:\w+>/<action:\w+>'=>'/module/<controller>/<action>',

'http://module.domain.<zone:local|com>/<controller:\w+>'=>'/module/<controller>',

'http://module.domain.<zone:local|com>'=>'/module',



I think this can be a solution, but I am not sure if this will work when you specify shorter routes (/module instead of /module/default/index). You can point to default controllers/actions but it will complicate configuration when you use non-standard default controllers/actions (other than DefaultController and index action)…

Thank you for answer!!!

I’ll try