Yii, wildcard -> web module for users subdomains

Hi!

I want to create in my app, something like cms, but so simply and easy.

Every user will have subdomain like "alias.myapp_domain.com".

Users have a module for manage web and other functions (not only web is the point of app).

I have an admin module for management whole application - users, payments etc.

I want to create "WEB Module" for handling every request "subdomain.myapp_domain.com".

Request of "myapp_domain.com" should go to main module, but every request of subdomain should be redirect to web module, where I want takie "subdomain" into app, and show appropriate website of user with this alias.

How to resolve this?

Maybe someone did something like this?

You can do this with the router. Have a look at section 5 here: http://www.yiiframework.com/doc/guide/1.1/en/topics.url

You will also need to setup a wildcard dns record and you need to make sure apache is directing all wildcard traffic to your app.

Thank You, but how Can I catch "alias".myapp_domain.com ?

You can parameterize the subdomain to a GET parameter with a router rule like this:




array(

    'http://<subdomain:\w+>.example.com/' => 'examplecontroller/exampleaction',

)



Then you can obtian the subdomain by using $_GET[‘subdomain’] anywhere in your code. Of course you need to change the rule and maybe add more rules to handle all the requests.