Custom Domain Mapping Question

Hi there, I am trying to allow my users to setup custom domain via Yii (1.1.14). i.e. http://www.anydomain.com -> http://username.myapp.com. Does anyone have any experience doing this in Yii? I am not sure what is the best approach and I have tried the following.

In my urlManager rules, I already have a bunch of rules that handle username in the subdomain. For example,


'rules'=>array(

...

'http://<user:[a-zA-Z0-9_-]+>.myapp.com' => 'controller/action/username/<user>',

...



Then, I added a new urlmanager rule:




...

array(

 'class' => 'application.components.ExampleUrlRule',

 ),

...



And in the parseUrl() function, I simply look up the custom url in DB and get the corresponding username. Then I tried to cheat a little by simply updating the $request->hostInfo to http://username.myapp.com. Then I run $manager->parseUrl($request) again so it re-uses my original rules which handles username in the subdomain.

This seems to be partially working. However, it doesn’t work when I am making an AJAX call to the custom domain name. I have a feeling it’s some sort of CORS restriction.

So again, my questions are:

  1. What is the suggested approach for doing custom domain masking for users?

  2. How do you handle cross domain AJAX calls with custom domains?

  3. How do you handle sessions correctly with custom domains?