create subdomain in yii for particalur controller

301 Views Asked by At

I am looking for answer in yii.I want to create subdomain in yii.I want to do url rewrite like this.This should be applied to only one controller not every.

from

http://abcd.com/directory-1/directory-2/CotrollerName/FunctionName/Argument1/

to

http://Argument1.abcd.com/directory-1/directory-2/CotrollerName/FunctionName/

Thanks in advance !!!

1

There are 1 best solutions below

2
On

A tricky solution will look like:

class ControllerName extends Controller {

//...

public function FunctionName($Argument1 = NULL) {

    if ($Argument1 === NULL)
        $Argument1 = preg_filter('/^([^\.]+)\.abcd\.com$/', '$1', $_SERVER['HTTP_HOST']);

    else
        $this->redirect("http://$Argument1.abc.com/.....");

    assert(!empty($Argument1));

 //.. more code here ...
}