Redirecting a domain or subdomain (e.g., login.example.com
) to another (e.g., abc.example.com
) can be done using various approaches. Below, we outline the steps to accomplish this on IIS (Internet Information Services), as well as alternative methods using .htaccess
, Nginx, DNS, PHP, and Cloudflare for those using different setups.
Redirecting domains in IIS
Option 1: Using IIS Manager
- Open IIS Manager:
Launch IIS Manager on your server.
In the Connections pane, locate and select the site corresponding to the subdomain login.example.com
.
- Enable HTTP Redirect:
In the Features View, double-click on HTTP Redirect.

- Check the box for Redirect requests to this destination, and enter:
https://abc.example.com
- Under Redirect Behavior:
- Check Redirect all requests to exact destination (rather than relative to destination).
- Select Permanent (301) as the redirect type.

- Apply Settings:
Click Apply in the right-hand pane to save your changes.
- Restart IIS:
To apply the changes, restart IIS by running the following command in the command prompt: iisreset
Option 2: Edit the Web.config File
If you prefer to configure the redirect manually, you can use a web.config
file. Place this file in the root directory of the login.example.com
site:
<configuration>
<system.webServer>
<httpRedirect enabled="true" destination="https://abc.example.com" httpResponseStatus="Permanent" />
</system.webServer>
</configuration>
Note: Ensure the HTTP Redirect module is installed on the server (see below if it isn’t).
Install the HTTP Redirect Module (If Necessary)
If the HTTP Redirect feature is not available in IIS Manager:
- Open Server Manager.
- Go to Add Roles and Features.
- In the Server Roles section, expand Web Server (IIS) > Web Server > Common HTTP Features.
- Check HTTP Redirect and complete the installation.
Alternative Methods for Redirecting Subdomains
1. Redirect domain using .htaccess
(For Apache Servers)
If you’re using Apache, you can redirect the subdomain by adding this to the .htaccess
file in the root directory of login.example.com
:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^login\.example\.com$ [NC]
RewriteRule ^(.*)$ https://abc.example.com/$1 [L,R=301]
- Explanation:
RewriteCond
checks if the request is coming tologin.example.com
.RewriteRule
redirects all requests toabc.example.com
with the same path ($1
).
2. Redirect domain using Nginx
For Nginx servers, add this configuration to the server block for login.example.com
:
server {
server_name login.example.com;
return 301 https://abc.example.com$request_uri;
}
After updating the configuration, reload Nginx:
sudo systemctl reload nginx
3. Redirect domain at the DNS Level
If you want to redirect using DNS, follow these steps:
- Go to your DNS management panel.
- Add a CNAME record for
login.example.com
pointing toabc.example.com
. - If your DNS provider supports it, you can also use a URL redirection service to create a 301 redirect.
Note: DNS-level redirection typically works for simple cases and doesn’t preserve paths. You can check your DNS delegation by going to https://tools.itgranules.com/tools/dns-lookup
4. Redirect domain using PHP
If you have PHP enabled on the server for login.example.com
, you can create an index.php
file with the following content:
<?php
header("Location: https://abc.example.com", true, 301);
exit();
This will issue a 301 redirect to the target subdomain.
5. Redirect domain using Cloudflare
If you use Cloudflare for DNS management, you can set up a redirect via Page Rules:
- Log in to your Cloudflare account.
- Go to the Page Rules section.
- Add a new rule:
- If the URL matches:
https://login.example.com/*
- Then the setting is: Forwarding URL → 301 Permanent Redirect
- Redirect to:
https://abc.example.com/$1
- If the URL matches:
- Save the rule.
Testing the domain redirect
After setting up the redirect, verify it:
- Open a browser and navigate to
http://login.example.com
orhttps://login.example.com
. - Ensure it redirects to
https://abc.example.com
. - Use tools like Redirect Checker to confirm the redirect status (301/302).
Conclusion
Redirecting one subdomain to another can be achieved through IIS configurations or alternative methods like .htaccess
, Nginx, DNS, PHP, or Cloudflare. For IIS, using the HTTP Redirect module or editing the web.config
file is the most straightforward solution. Choose the method that aligns best with your hosting environment and requirements.