Brinkster Knowledge Base

KB Home   /  Support  /  Domain  /   Domain redirect
Domain redirect Articles
How to direct domains / subdomains?
By default, all domain names and subdomain names are directed to the root folder of your website. For Windows hosting accounts this is the "webroot" folder; For linux accounts this is the "public_html" folder. Due to the nature of Brinkster's shared hosting plans, multiple websites on the same account need to be directed through an isapi filter by use of .htaccess or through code.

Using Mod_rewrite to control your domain names will allow you to host your domains and sub domains in sub folders of your website's root folder, and when a visitor browses to your site, the URL will NOT change.


* Mod_rewrite / URL rewrite is not available to Level 1 accounts. This is a feature of Level 2 and Level 3 accounts. If you have a Level 1 account, you will need to use the ASP, PHP, or HTML code redirects.

**Joomla and domain redirection.**
In order for Joomla to function properly while using the .htaccess file to control your domains, you may need to make a minor configuration update to your joomla configuration.php file.
Click here for more details.

*** ASP.NET and isapi filtering with the helicon filter***
If you are running multiple ASP.NET applications with different versions (some are set to 2.0 and some are set to 3.5) you will be unable to use the isapi filtering to direct your domains to your applicaiton root folders. Due to a limitation with the Helicon isapi filter we have running, the .htaccess code is not able to handle multiple ASP.NET versions. You will need to have all of your applications set to ASP.NET 2.0 or all of them set to ASP.NET 3.5

htaccess information - For Windows

1) Sample 1 will automatically direct all domain names and the www. sub domain to folders named exactly the same as the domain itself. Sub domains will be directed to their own folder.
    1a) www.domain.com and domain.com will be directed to the folder named "domain.com"
    1b) admin.domain.com will be directed to the folder named "admin.domain.com"

2) Sample 2 will direct all domain names to folder names that you specify. You will need to make a separate entry for each domain and sub domain in your htaccess file if you are using sample 2.
    2a) www.domain.com and domain.com will be directed to the folder of your choosing.
    2b) admin.domain.com will be directed to 
the folder of your choosing.
    2c) If you do not specify an entry for your domain in the .htaccess file when using sample 2, the domain / subdomain will be directed to the main file within the root folder of your website.




Windows                      Top of Page

ISAPI Filtering / mod_rewrite (For Windows Only)
For more information on using isapi rewrite in Windows, see the documentation on the rewrite engine that is supported at Brinkster.
http://www.helicontech.com/isapi_rewrite/doc/


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.

Sample 1 (Automatic redirection for all domains and subdomains)
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.
#Turns the rewrite engine on.
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]



Sample 2
(Manual redirection for all domains and subdomains)
This .htaccess file sample will direct all domain names and sub domains to folder names that you specify.


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]





Linux                     Top of page

ISAPI Filtering / mod_rewrite (For Linux Only)

Step 1: Create a .htaccess file with the file manager inside the public_html folder of your website.
Step 2: Add your desired sample to the .htaccess file.

Sample 1 (Manual redirection for all domains and subdomains)
This .htaccess file sample will direct all domain names and sub domains to folder names that you specify.


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$
RewriteCond %{REQUEST_URI} !^/folder1/
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$
RewriteCond %{REQUEST_URI} !^/folder2/
RewriteRule ^(.*) folder2/$1 [NC,L,NS]

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






 ASP, PHP, and HTML Code samples for redirecting domain names.



ASP                     Top of Page


This ASP sample will *include* content from another page, leaving the URL in the URL bar of the web browser alone.
We suggest using the include sample only when including other files from within your root directory.

<%@Language=VBScript%>
<%
SiteNameURL =  Request.ServerVariables("SERVER_NAME")
Select Case SiteNameURL
            
Case "yourdomain.com"
                %><!-- #Include File="page1.asp" --><%
            
Case "www.yourdomain.com"
                
%><!-- #Include File="page1.asp" --><%
            
Case "yourotherdomain.com"
                %><!-- #Include File="page2.asp" --><%
            
Case "www.yourotherdomain.com"
                
%><!-- #Include File="page2.asp" --><%
            
Case "subdomain1.yourdomain.com"
                
%><!-- #Include File="page3.asp" --><%
            
Case "subdomain2.yourdomain.com"

                %><!-- #Include File="page4.asp" --><%

            
Case Else 'Everything other than cases specified above
                
%><!-- #Include File="other.asp" --><%
End Select
%>




This ASP sample will *redirect* the URL in the address bar.
We suggest using the redirect sample when you have a sub folder which contains the contents of your website.

<%@Language=VBScript%>
<%
SiteNameURL =  Request.ServerVariables("SERVER_NAME")
Select Case SiteNameURL
            
Case "yourdomain.com"
                
Response.Redirect "page1.asp"
            
Case "www.yourdomain.com"
                
Response.Redirect "page1.asp"
            
Case "yourotherdomain.com"
                
Response.Redirect "page2.asp"
            
Case "www.yourotherdomain.com"
                
Response.Redirect "page2.asp"
            
Case "subdomain1.yourdomain.com"
                
Response.Redirect "page3.asp"
            
Case "subdomain2.yourdomain.com"
                Response.Redirect "page4.asp"

            
Case Else 'Everything other than cases specified above
                
Response.Redirect "other.asp"
End Select
%>



PHP                     Top of Page

This PHP sample will *include* content from another page, leaving the URL in the URL bar of the web browser alone.
We suggest using the include sample only when including other files from within your root directory.

All domain name entries should be in lower case.

<?php
$SiteNameURL = $_SERVER['HTTP_HOST'];

switch (strtolower($SiteNameURL)) {

case "domain.com": //MUST BE LOWER CASE
            
include 'page1.php';
            
break;
case "www.domain.com": //MUST BE LOWER CASE
            include 'page1.php';
            
break;
case "yourotherdomain.com": //MUST BE LOWER CASE
            
include 'page2.php';
            
break;
case "www.yourotherdomain.com": //MUST BE LOWER CASE
            
include 'page2.php';
            
break;
case "subdomain1.domain.com": //MUST BE LOWER CASE
            include 'page3.php';
            
break;
case "subdomain2.domain.com": //MUST BE LOWER CASE
            
include 'page4.php';
            
break;
default:
            
include 'other.php';
}
?>


This PHP sample will *redirect* the URL in the address bar.
We suggest using the redirect sample when you have a sub folder which contains the contents of your website.

All domain name entries should be in lower case.

<?php
$SiteNameURL = $_SERVER['HTTP_HOST'];

switch (strtolower($SiteNameURL)) {

case "domain.com": //MUST BE LOWER CASE
            
header("Location: http://" . $_SERVER['HTTP_HOST'] . "/page1.php");
            
break;
case "www.domain.com": //MUST BE LOWER CASE
            
header("Location: http://" . $_SERVER['HTTP_HOST'] . "/page1.php");
            
break;
case "yourotherdomain.com": //MUST BE LOWER CASE
            header("Location: http://" . $_SERVER['HTTP_HOST'] . "/page2.php");
            
break;
case "www.yourotherdomain.com": //MUST BE LOWER CASE
            
header("Location: http://" . $_SERVER['HTTP_HOST'] . "/page2.php");
            
break;
case "subdomain1.domain.com": //MUST BE LOWER CASE
            
header("Location: http://" . $_SERVER['HTTP_HOST'] . "/page3.php");
            
break;
case "subdomain2.domain.com": //MUST BE LOWER CASE
            
header("Location: http://" . $_SERVER['HTTP_HOST'] . "/page4.php");
            
break;
default:
            header("Location: http://" . $_SERVER['HTTP_HOST'] . "/other.php");
}
?>





HTML / Javascript                      Top of Page
 

The following example uses JavaScript code. You will need to save the page as an HTML document, using .html or .htm as the file extension. This code sample will redirect visitors to the corresponding page, changing the URL.

<html>
<head>
<script language=javascript>

var whois=location+" "

if (whois.indexOf("yourdomain.com") != -1)
            
{ window.location ="page1.html" }

if (whois.indexOf("www.yourdomain.com") != -1)
            
{ window.location ="page1.html" }

if (whois.indexOf("yourotherdomain.com") != -1)
            
{ window.location ="page2.html" }

if (whois.indexOf("www.yourotherdomain.com") != -1)
            
{ window.location ="page2.html" }

if (whois.indexOf("subdomain1.yourdomain.com") != -1)
            
{ window.location ="page3.html" }

if (whois.indexOf("subdomain2.yourdomain.com") != -1)
            
{ window.location ="page4.html" }
</script>
</head>
<body>
</body>
</html>