subdomain rewrite rules

Does Yii supports subdomain rewrite rules? Like having xx.mydomain.com, yy.mydomain.com etc? I know Zend Does.

Bump.

Nope. Maybe you can elaborate how this would be used?

if i have a domain name i use that is domain.com currently you can use domain.com/moduleID/controllerID/actionID to make this redirect to a certain action in a controller. You can also write rules, But all of this will need to be after the domain and as the path info. Zend allows you to do actionID.domain.com and it will redirect that to that action based on a rule you specify.

Yes, I also would like to be able to do the following:

username.domain.com - goes to the user’s profile

blog.domain.com - writing about the domain

pics.domain.com - checkout all our photo’s

etc.

I’m also interested in something like that in order to do multi-language sites based on the subdomain.

http://de.example.com/

http://en.example.com/

Also different url-rules should be supported based on the subdomain (and throw an error even if the path is available at the other subdomain).

http://de.example.com/kontakt/

http://en.example.com/contact/

I have to write my own UrlManager class, I guess.

Yea that’s an example of one way of using it.

强烈关注

Bump.

Is this something the 1.0 series will have?

You could use a combination of dynamic controller and lookup the virtual host by URI. Then use the following pattern in your own subclassed URLManager:




class UrlManager extends CUrlManager

{

  private function getRules()

  {

     switch($site->type) {

       case 'admin':

         $rules = array(

          ...

         );

       case 'vhost':

          ...

       case 'blah':

         ...

     }

     return $rules;

  }


  protected function processRules()

  {

    $this->rules = $this->getRules();

    return parent::processRules();

  }

}



You can also define your getRules method like so, to continue defining rules in the config, but then you lose the ability to alter the rules dynamically.




private function getRules()

{

  return Yii::app()->param->rules[SiteController::getSite()->type];

}



and put your rules in params:




return array(

  'params' => array(

    'rules' => array(

      'admin' => array(

         ...

      ),

      ...

    ),

  ),

);



This gives you customized views, rules and controllers per virtual domain.

EDIT:

On second thoughts, the UrlManager’s rules property can be used as is, instead of adding it as a params entry.

In that case, make sure your rules are grouped into site types as above (under the urlManager component’s entry in config/main.php), and use the following in getRules():




private function getRules()

{

  return $this->rules[SiteController::getSite()->type];

}