Catch-All Virtual Sub-Domains

This section contains the codes and tips to improve the ranking of your site into the search engines. It will also contain info regarding the Mod Rewrite technique.

Catch-All Virtual Sub-Domains

Postby Web Guru on May 12th, 2008, 8:10 am

If you have setup your DNS settings to catch-all your sub-domains to the root directory, then you can handle the sub-domain requests using .htaccess file. The re-write rules to catch and process the sub-domain requests are as follows:

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.
User avatar
Web Guru
 
Posts: 68
Joined: March 24th, 2008, 7:59 am
Location: Lahore, Pakistan

Return to SEO - Search Engine Optimization

Who is online

Users browsing this forum: No registered users and 0 guests

cron