Help Docs Control Panel Guides Cloud Sites Guide ASP.NET and IIS in Cloud Sites Redirect Subdomains using ASP and ASP.NET in Cloud Sites

Redirect Subdomains using ASP and ASP.NET in Cloud Sites

You can redirect a subdomain to a subdirectory by using ASP or ASP.NET code. Find examples of how to redirect your subdomains in this article.

Note:

The code provided below is only an example. Your specific website may require different code. As outlined in our Terms of Service and Cloud Sites Spheres of Support Expectations, we are unable to help you troubleshoot code issues. We recommend speaking with your developer before implementing any scripts.

You can redirect a subdomain to a subdirectory by using ASP or ASP.NET code. When the requests are redirected by using an ASP file, the URL in the browser for redirected domains shows the correct domain name and directory name where the request is being redirected. You can also redirect the requests to a specific file.

You can see examples of how to redirect your subdomains below.

Subdomain Examples

Below are examples of domains that you want redirected to a subdomain and the format the URL would be in for each example.

http://subdomain1.YourHostedDomainName.com > 
http://subdomain1.YourHostedDomainName.com/subdomain1
http://subdomain2.YourHostedDomainName.com > 
http://subdomain2.YourHostedDomainName.com/subdomain2
http://subdomain3.YourHostedDomainName.com > 
http://subdomain3.YourHostedDomainName.com/subdomain3/home.asp

Using the domains listed above, you can see in the following sample script how to redirect a subdomain.

Note:

You will need to place the script as the default document on your document root

<%
If InStr( UCase(Request.ServerVariables("SERVER_NAME")),
 UCase("subdomain1.YourHostedDomainName.com") ) > 0 Then
  Response.Redirect("/subdomain1")
ElseIf InStr( UCase(Request.ServerVariables("SERVER_NAME")), 
UCase("subdomain2.YourHostedDomainName.com") ) > 0
Then
  Response.Redirect("/subdomain2")
ElseIf InStr( UCase(Request.ServerVariables("SERVER_NAME")), 
UCase("subdomain3.YourHostedDomainName.com") ) > 0
Then
  Response.Redirect("/subdomain3/home.asp")
End If
%>

You can edit this script with your own domain name and subdomain URLs then copy and paste it into your document root.

Was this article helpful?