Moving a subdomain to the main domain: use bulk 301 redirects when paths stay the same

ProcrustesPR

When moving a subdomain to the main domain, you can use bulk 301 redirects instead of setting up each page individually, provided that the paths on both domains correspond exactly. The approach below uses .htaccess to filter requests by source hostname and port, then applies a single set of rules to capture the paths and redirect to the main domain while preserving query parameters. This works for a migration where only the domain changes, not the paths. It does not guarantee when Google will update its index or that rankings will stay the same.

ProcrustesPRProcrustesPRHow should you balance CNAME convenience and performance?

First, check: can every old path stay the same on the main site?

Whether you can redirect in bulk depends not on the number of pages, but on whether the source and destination follow a consistent mapping rule. For example, /products/item-a on the test site remains /products/item-a on the main site, and you also want to preserve any ?ref=test query string. That is the scenario covered by the example below.

  • Only the hostname differs: you can use the path-preserving bulk rules below.
  • The paths also change, such as /old-item becoming /products/new-item: keeping the old path will not lead to the correct destination.
  • Some pages have different paths: confirm their destination URLs first rather than applying the same rules to every page.

Match the source hostname, then add the captured path to the main site’s URL

The .htaccess example below comes from Webmasters Stack Exchange. It handles ports 80 and 443 separately and restricts the source to beta.mysite.com. Before using it, replace the example hostnames with your actual domains and confirm that your environment supports this type of configuration.

RewriteEngine on
Options +FollowSymlinks -MultiViews

RewriteCond %{SERVER_PORT} =80
RewriteCond %{HTTP_HOST} ^beta\.mysite\.com$ [NC]
RewriteRule ^/?(.*)$ http://www.mysite.com/$1 [R=301,L,QSA,NE]

RewriteCond %{SERVER_PORT} =443
RewriteCond %{HTTP_HOST} ^beta\.mysite\.com$ [NC]
RewriteRule ^/?(.*)$ https://www.mysite.com/$1 [R=301,L,QSA,NE]

These rules use $1 to add the captured path after the destination hostname, rather than sending every old page to the homepage. R=301 specifies the redirect status code, while QSA appends the original query parameters. Note that the example handles HTTP and HTTPS separately; it does not redirect both to HTTPS.

Bulk redirects still need destination checks

A separate discussion on Warrior Forum says that redirecting specific pages to a new domain requires a redirect for each page. However, the excerpt does not describe the path structure, so it does not establish that every migration requires individual rules. For the scenario covered here, where paths stay the same on both sites, the bulk example above is more applicable.

Before applying the rules, check the homepage, a deeply nested path, and a URL with query parameters. Confirm that the destination domain is correct, the path stays the same, the parameters are preserved, and the corresponding page exists on the main site. If you want to switch entirely to HTTPS, or if some pages have changed paths, do not treat the example above as a complete solution.

ProcrustesPRProcrustesPRShould you use a 302 redirect to a temporary alias for the new server during a DNS update?

Redirecting a subdomain to the main domain: perspectives from across the web

Can the same rule handle paths with different depths or file extensions?

Yes. The example's path-capture pattern is not limited to a particular directory depth or file extension, so those differences alone do not require individual redirects. However, the source request must still meet the hostname and port conditions, and the main site must have a corresponding page at the same path. A URL matching the rule does not mean its destination page exists.

Does the example also apply to other subdomains or nonstandard ports?

Not necessarily. The example's hostname condition matches only the specified beta subdomain, and it checks ports 80 and 443 separately. Other hostnames or ports do not meet these conditions. If your actual environment differs, first confirm which hostname and port the rules will see when processing requests; do not assume the example already covers them.

ProcrustesPRHow does HSTS protect websites and subdomains?

References

  1. Redirect 301 all the links of 3 old domains to 3 the links in the new domainwww.warriorforum.com — Source used in the article above.
  2. SEO: Full Redirect from Subdomain to Root Domainwebmasters.stackexchange.com — Discusses: Can the same rule handle paths with different depths or file extensions?; Does the example also apply to other subdomains or nonstandard ports?

Related articles

How should you balance CNAME convenience and performance?Should you use a 302 redirect to a temporary alias for the new server during a DNS update?How does HSTS protect websites and subdomains?How do SSL certificates protect websites, and why are they needed?Should a Tumblr blog use the platform’s domain or the company’s domain?What types of URLs are there, and what are they used for?When should you use relative or absolute paths in WordPress?What are www subdomains and relative links used for?
ProcrustesPR
ProcrustesPR