---
title: "Redirect Subdomains using ASP and ASP.NET in Cloud Sites"
source: "https://docs.nexcess.com/hosting/cloud-sites/asp-net-and-iis/redirect-subdomains-using-asp-and-asp-net-in-cloud-sites/"
description: "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."
vertical: "Hosting"
date: "2024-03-04"
last_modified: "2026-07-20"
---

# Redirect Subdomains using ASP and ASP.NET in Cloud Sites

| ### **Note:** |
|---|
| The code provided below is only an example. Your specific website may require different code. As outlined in our [Terms of Service](https://www.liquidweb.com/policies/terms-of-service/) and [Cloud Sites Spheres of Support Expectations](https://www.liquidweb.com/help-docs/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](https://www.liquidweb.com/vps-hosting/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.
