- Code: Select all
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ [NC]
RewriteCond %1 ^www$ [NC]
RewriteCond /home/user_name/public_html/%1 -d
RewriteCond %{REQUEST_FILENAME} !^/home/user_name/public_html/%1
RewriteRule ^(.*)$ /%1/$1 [L]
This script will redirect the request like http://subdomain.domain.com to subdomain folder present on the root folder.
The user_name is your user name, if you are using cpanel based hosting account, otherwise replace the complete path with your absolute server path.
This script is tested and i am using this on my webistes. You are welcome to discuss any issuues in implementing it on your website.