How can I use ASP to ReDirect a user based on the domain name?

Domain Names
This information is useful when you have multiple domains pointing to your IP and you want to redirect to the proper page according to domain name. The following ASP Script shows a simple way to redirect based on the domain name: 

<%
  Dim HTTPHost
  HTTPHost = Request.ServerVariables("HTTP_HOST")

  If InStr(Request.ServerVariables("HTTP_HOST"), "domain1.com") Then
     Response.ReDirect "http://www.newlocation.com"
  
  ElseIf InStr(Request.ServerVariables("HTTP_HOST"), "doman2.com") Then
     Response.ReDirect "/subfolder/"
     
  Else
     Response.ReDirect "http://www.domain.com"
  End If
%>

You can place this script as your default.asp and place your web content in sub-webs or subdirectories.

Add Feedback