Is there any way in mod-rewrite that sub directory refer to a sub domain.
so:
maindomain.com/something refer to something.maindomain.com
thanks!
Is there any way in mod-rewrite that sub directory refer to a sub domain.
so:
maindomain.com/something refer to something.maindomain.com
thanks!
I share here my hard tested RewriteRule set, hope that you can adapt to your usage:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^((?!www).*)\.maindomain\.com$
RewriteRule ^(.*)$ http://www.maindomain.com/%1/$1 [L]
It tells apache to capture the host name that is not www in the RewriteCond backreference %1 (percentage 1). And capture the relative url in RewriteRule backreference $1 (dollar 1).
It does this:
http://east.maindomain.com/ => http://www.maindomain.com/east/
http://east.maindomain.com/asia/us/index.php => http://www.maindomain.com/east/asia/us/index.php
RewriteEngine On
RewriteCond %{HTTP_HOST} ^((?!www).*)\.maindomain\.com$
RewriteRule ^(.*)$ http://www.maindomain.com/%1/$1 [R,L]