Redirect a subdomain to a subdirectory

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 the browser for redirected domain will show the correct domain and the directory name where the request is redirecting, you can also redirect the request to the specific file

Ex:

http://subdomainA.yourdomain.com --> http://subdomain1.yourdomain.com/subdomainA

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

http://subdomainC.yourdomain.com --> http://subdomain3.yourdomain.com/subdomainC/index.asp

The below smaple code can be use to redirect a subdomian. You will need to place it as defult document to 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
%>

Please note

-Please replace susubdomain.yourdomain.com with your actual subdomain URL.

-Replace /subdomain with your actual subdirectory name.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

SQL server- network related or instance-specific error happened while connection establishing

  Instance-specific or network related error happening while connecting to SQL server   Please...

OleDB connection string examples

OleDB connection string examples MS Access (Jet) "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA...

Do you allow custom COM components?

Do you allow custom COM components? We are not offering to install the custom COM components...

Error when accessing a WCF services

Error when accessing a WCF services Error when accessing a WCF service: "IIS specified...

How to cache static contents to client with UseMaxAge?

You can consider to caches static contents to the client with UseMaxAge if your website has too...

Powered by WHMCompleteSolution