Pointing a Domain Alias to a Subdirectory

Using an .asp script it is possible to redirect the incoming requests for the domain alias to a desired subdirectory of the site. Each subdirectory would have its own default document and web content. This allows multiple domain names to use a single hosting plan to serve up a different website for each of the domains.

To put it another way, a "normal" domain alias setup points several different domain names to the same website, here an extra step is taken to "detect" which domain name was entered into the browser address field and "execute" the contents of different subdirectories based on that value.

The most common way to process a secondary domain alias using ASP code is to use the incoming host header value to select a redirect page. The incoming host header is stored in the server variable "HTTP_HOST", and the Redirect method of the Response object is used to perform the redirection.

For example, the following code will examine the host header and redirect to a subfolder.

If you use relative URL's in your Redirect statements as shown above, the client browser will continue to use the original alias domain name. In other words, by using URL's like "/this" or "/that" the original alias domain name will appear in the client web browser URL bar after the redirect has completed. If your redirect parameter looks like "http://www.this.that" then the value in the client browser will show the full URL used in the redirect, not the one from the original request to your alias.

<%
  Option Explicit
  Response.Buffer = True

 

  Dim HostURL
  HostURL = Lcase(Request.ServerVariables("HTTP_HOST"))

 

  Select Case HostURL ' Find which site to redirect to
    Case "
www.widgets.com", "widgets.com"
       Response.Status="301 Moved Permanently"
       Response.AddHeader "Location", "widgets/default.htm"
    Case "
www.tiddleywinks.com", "tiddleywinks.com"
       Response.Status="301 Moved Permanently"
       Response.AddHeader "Location", "tiddlywinks/default.htm"
    Case "
www.fiddlesticks.com", "fiddlesticks.com"
       Response.Status="301 Moved Permanently"
       Response.AddHeader "Location", "fiddlesticks/default.htm"
  End Select
  %>

All that needs to be done is to insert the contents of the above example, suitably customized by replacing the example domain and folder names, into the main .asp default document located in the website root folder.

Note: We cannot configure our DNS to point a domain name alias to a subdirectory of your site. We can only point the alias to the root folder of your site.

Add Feedback