Knowledgebase: Domain Names / DNS
How to make a sub-domain point to a sub-directory using ISAP_Rewrite v3
Posted by Joe Rebis (Import) on 14 June 2010 01:16 PM

 

Using ISAPI rewrite v3 to point a sub-domain to a sub-directory:

ISAPI Filtering / mod_rewrite (For Windows Only) AND You must have a dedicated IP for this method to work correctly.

Add an "A" record for the sub-domain in the DNS zone for the primary domain. Then you can rewrite the sub-domain URLs so they point to a sub-directory without it showing in the URL. You can repeat the rules to add additional sub-sites. If you create a file called httpd.ini (using notepad) and put it in your WWWROOT folder for the website with the sub-domains you can add the following code to create a rule for it to point to a sub-directory off the website. You can duplicate the second part of the rule to add more as needed. If you plan to install a web application (e.g. DotNetNuke or WordPress), you will want to create a Virtual Directory on the website pointing to the same folder so IIS will enable it for applications.

NOTE: we will be upgrading to the latest version of the URL rewriting tool sometime soon. Please pay close attention to make sure this rule will be compatible with the new version.

Method 1:

[ISAPI_Rewrite]

#Rules used to emulate a website in a sub-directory (old sub-domain way).

#Rename this file httpd.ini and place in the main website WWWROOT folder.

#Fix missing slash char on folders.

RewriteCond Host: (.*)

RewriteRule ([^.?]+[^.?/]) http\://$1$2/ [I,R]

#Emulate an additional website.

RewriteCond Host: (?:sub-domain\.)?your-domain\.com

RewriteRule (.*) /your-sub-dirdectory$1 [I,L]

**Please Note** Replace 'sub-domain' and 'your-domain' with your website.

We don't guarantee this method will work 100% of the time and in 100% of situations.

 

Method 2: for .htaccess Automatic redirection for all domains and subdomains

Step 1: Create a .htaccess file with the file manager inside the root folder of your website.

Step 2: Add your desired sample to the .htaccess file.

This .htaccess file sample will direct all domain names automatically to folders named identical to the domain. Sub domains will be automatically directed to their own folder.

Use this sample if you have many domain names that you want to automatically direct to their own folder, and you do not want to make a separate entry for each domain in your .htaccess file.

RewriteEngine on

#Fix missing trailing slash character on folders.
RewriteRule ^([^.?]+[^.?/])$ $1/ [R,L]

#Maps all domain requests to folders named same as domain.
RewriteCond %{HTTP:Host} ^(www\.)?(.+)
RewriteRule (.*) /%2/$1 [NC,L,NS]

 

Method 3: for .htaccess files Manual redirection for all domains and subdomains

1) Use this sample if you have multiple domain names that you want to direct to the same folder.

2) Use this sample if you want to direct your domains to folders with names other than mydomain.com and subdomain.mydomain.com

3) You will need to make a separate entry for each of your domains in your .htaccess file.

#Turns the rewrite engine on.
RewriteEngine on

#Fix missing trailing slash character on folders.
RewriteRule ^([^.?]+[^.?/])$ $1/ [R,L]

#www.domain.com and domain.com will map to the folder {root}/folder1/
RewriteCond %{HTTP:Host} ^(?:www\.)?domain\.com$
RewriteRule (.*) /folder1/$1 [NC,L,NS]

#www.otherdomain.com and otherdomain.com will map to the folder {root}/folder2/
RewriteCond %{HTTP:Host} ^(?:www\.)?otherdomain\.com$
RewriteRule (.*) /folder2/$1 [NC,L,NS]

#subdomain.domain.com will map to the folder {root}/folder3/
RewriteCond %{HTTP:Host} ^(?:subdomain\.domain\.com)?$
RewriteRule (.*) /folder3/$1 [NC,L,NS]

 

Also See 

 

Also See: Domain & DNS KB articles | Email Settings POP3 / IMAP | Check email online | Email Troubleshooting | Adding an email to your hosting account WINDOWS / LINUX

Contact Support

If you are still having issues, please contact us for further help.
1-877-EPHOST1 | support@ephost.com

 

 

(169 vote(s))
Helpful
Not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).

Copyright © 2015 EPhost, Inc. All rights reserved.