How to redirect a subdomain to a subdirectory

Programming, error messages and sample code > sample code
You can redirect a subdomain to a subdirectory by using ASP or ASP.net code.

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.yourdomain.com --> http://subdomain1.yourdomain.com/subdomain1

http://subdomain2.yourdomain.com --> http://subdomain2.yourdomain.com/subdomain2

http://subdomain3.yourdomain.com --> http://subdomain3.yourdomain.com/subdomain3/home.asp

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.yourdomain.com") ) > 0 Then 
        Response.Redirect("/subdomain1") 
ElseIf InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("subdomain2.yourdomain.com") ) > 0 Then 
        Response.Redirect("/subdomain2") 
ElseIf InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("subdomain3.yourdomain.com.com") ) > 0 Then 
        Response.Redirect("/subdomain3/home.asp") 
End If 
%> 

Note:
  1. Replace subdomain.yourdomain.com with your actual subdomain URL.
  2. Replace /subdomain with your actual subdirectory name.