If you have plenty of sub-domains and every subdomain routes in another directory on the server, This can be done dynamically.
Add folling in httpd.conf/httpd-vhost.conf
<\VirtualHost *:80\>
ServerName www.kishor.com
ServerAlias www.kishor.com
ServerAlias kishor.com
ServerAlias *.kishor.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^kishor.com
RewriteRule ^(.*)$ /var/www/html/$1 [L]
RewriteCond %{HTTP_HOST} ^www.*
RewriteRule ^(.*)$ /var/www/html/$1 [L]
RewriteCond %{HTTP_HOST} ^(.*)\.kishor\.com
RewriteRule ^(.*)$ /%1/$1 [L]
ErrorDocument 404 http://www.kishor.com
<\/VirtualHost\>
As you can see, the DocumentRoot is //var/www/html/. This is the directory where all other sub-directories for the sub-domains are located.
We use the RewriteEngine to decide which directory we want. The first RewriteCond is to route the domain without any sub-domain into the www directory. The second RewriteCond demonstrates how the third RewriteCond works with any subdomain.
www.kishor.com => /var/www/html/www/
test.kishor.com => /var/www/html/test/
gavali.kishor.com => /var/www/html/gavali/
Finally setup your domain as wildcard domain *.kishor.com in your DNS and enjoy the Dynamic Hosting.
Add folling in httpd.conf/httpd-vhost.conf
<\VirtualHost *:80\>
ServerName www.kishor.com
ServerAlias www.kishor.com
ServerAlias kishor.com
ServerAlias *.kishor.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^kishor.com
RewriteRule ^(.*)$ /var/www/html/$1 [L]
RewriteCond %{HTTP_HOST} ^www.*
RewriteRule ^(.*)$ /var/www/html/$1 [L]
RewriteCond %{HTTP_HOST} ^(.*)\.kishor\.com
RewriteRule ^(.*)$ /%1/$1 [L]
ErrorDocument 404 http://www.kishor.com
<\/VirtualHost\>
As you can see, the DocumentRoot is //var/www/html/. This is the directory where all other sub-directories for the sub-domains are located.
We use the RewriteEngine to decide which directory we want. The first RewriteCond is to route the domain without any sub-domain into the www directory. The second RewriteCond demonstrates how the third RewriteCond works with any subdomain.
www.kishor.com => /var/www/html/www/
test.kishor.com => /var/www/html/test/
gavali.kishor.com => /var/www/html/gavali/
Finally setup your domain as wildcard domain *.kishor.com in your DNS and enjoy the Dynamic Hosting.
Comments