Multi-Tenant Domain Mapping

Ok, I try to build a SAAS that can route multiple domains and trigger the appropriate view.

I need to:

[color="#0000FF"]

1- Parse the domain:

"http://exemple.com" to "exemple"

"http://sub.exemple.com" to "sub" + "exemple"

2- Compare with DB to get tenantID

3- Display the view with the correct domain "http://exemple.com/site/whatever"[/color]

Now I tried to understand URLmanager my guess would be something like this:




'http://<testSub:\w+>.<testDomain:\w+>.com/'=>'site/index',

'http://<testDomain:\w+>.com/'=>'site/index'



Now I would love to access the domain and subdomain like this, it would be awesome…




$mySubDomain = Yii::app()->params['testSub'];

$mydomain = Yii::app()->params['testDomain'];



[color="#FF0000"]Basically, I try to route multiple domains with a DB. How can I extract the domain name and still have the right URL in the address bar? [/color]

Thank you for your time :lol:

up! :rolleyes:

Please take a look at URL Management on the guide and at dburlmanager for inspiration.

Then you’ll be able to do it.

Please post again if you need specific instructions.

Thank you, I will have a shot at it but is there a way I can test multiple domains locally without paying parking?

Yes. You can setup fake domain names on your hosts file.

Of course, I totally forgot about that.

Thank you :lol: