I’m doing a website with Yii, which consists of different modules that should be accessed from different top level domains. I need, because of that, that every base depends on the module. Plus, the country code should also be checked and sent as a get parameter. Something like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.]+)\.micrositedomain\.com$
RewriteRule ^(.*)$ http://bigsite.com/microsite/$1?lang=en [QSA]
RewriteCond %{HTTP_HOST} ^([^.]+)\.micrositedomain\.es$
RewriteRule ^(.*)$ http://bigsite.com/microsite/$1?lang=es [QSA]
RewriteCond %{HTTP_HOST} ^([^.]+)\.micrositedomain2\.com$
RewriteRule ^(.*)$ http://bigsite.com/microsite2/$1?lang=en [QSA]
RewriteCond %{HTTP_HOST} ^([^.]+)\.micrositedomain2\.es$
RewriteRule ^(.*)$ http://bigsite.com/microsite2/$1?lang=es [QSA]
However, I’m not pretty sure where to handle this. It should obviously be in an .htaccess in the root, but I don’t know how to mix it with my .htaccess already there:
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
Also, I’m pretty sure that my hosting administrators should point each domain (www.micrositedomain.com, http://www.micrositedomain2.com…) to bigsite.com root, not each module, but I can’t really assure that.
Which step by step should I follow to accomplish that?
tl;dr
For those in a hurry, I want to:
- Rewrite urls from different domains/country codes to a single domain, and pass those parameters.
- Tell my hosting administrator where the domains should point to.
How would you solve this in my situation?
I’m not sure how to make it in .htaccess, but you could make it in yii config. Try something like this
After that you should put some MyController.php in components folder
All your controllers should extend this.
All your domains should point to directory with your application