Home » Categories » Multiple Categories

How do I redirect a subdomain to a subdirectory?

When the requests are redirected using an ASP file, the URL in browser for redirected domains will show the correct domain name and the directory name where the request is being redirected. You can also redirect the requests to a specific file.

For example :

http://subdomain1.YourHostedDomainName.com redirect to http://subdomain1.YourHostedDomainName.com/subdomain1

http://subdomain2.YourHostedDomainName.com redirect to http://subdomain2.YourHostedDomainName.com/subdomain2

The following is a sample script that you can use to redirect a subdomain. You will need to place it as default document on your document root.

     If InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("subdomain1.YourHostedDomainName.com") ) > 0 Then
         InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("subdomain2.YourHostedDomainName.com") ) > 0 Then
         InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("subdomain3.YourHostedDomainName.com") ) > 0 Then
     End If

1. Replace subdomain#.YourHostedDomainName.com with your actual subdomain URL.
2. Replace /subdomain# with your actual subdirectory name
3. In the last redirection statement in the example, we show how to redirect to a specific file
Attachments Attachments
There are no attachments for this article.
Related Articles RSS Feed
Domain Name Server (DNS) Amplification Attack
Viewed 9105 times since Wed, Oct 15, 2014
About Azure Key Vault
Viewed 1166 times since Mon, Nov 2, 2020
Do you allow custom COM components?
Viewed 2487 times since Tue, May 1, 2012
How to Solve an Error Message "Validation of viewstate MAC failed"
Viewed 8758 times since Tue, Apr 2, 2013
I get an error Server.CreateObject Failed when I try to use CDONTs. What can I do?
Viewed 2552 times since Tue, May 1, 2012
Sample Code to Send email using ASP.NET1.1
Viewed 4998 times since Tue, May 1, 2012
I receive this error message: "Directory Listing Denied. This Virtual Directory does not allow contents to be listed."
Viewed 10199 times since Mon, Apr 30, 2012