Showing posts with label Subdomain. Show all posts
Showing posts with label Subdomain. Show all posts

Wednesday, October 13, 2010

How to create subdomains using htaccess?

First, you should set all subdomains to one directory in your web server config.

like this one below: 
ServerName  mydomain.com
ServerAlias   *.mydomain.com
Second, add this code to your .htacess file

RewriteEngine on
# SUB DOMAINS
RewriteCond %{http_host} !www\.([a-z0-9-]+)\.([a-z0-9-]{2,5})$ [NC]
RewriteCond %{http_host} ^(www.)?([a-z0-9-]+)\.([a-z0-9-]+)\.([a-z0-9-]{2,5})$ [NC]
RewriteRule (.*) /clients/%2/$1 [L]
# /SUB DOMAINS 


Finally, you should create a /clients/ folder in the main directory. Now every folder under /clients/ folder is a subdomain
For ex. If you have a test/ folder under the /clients/ folder, you can call the folder test.mydomain.com