Redirecting a subdomain means sending visitors and search engines from an address such as blog.example.com to another URL, such as example.com/blog. The correct setup depends on where the subdomain is hosted, which server software handles its traffic, and whether you want to preserve individual page paths.
If you are searching for how to redirect subdomain traffic, the short answer is to configure a permanent 301 redirect at the web server, hosting control panel, reverse proxy, or edge platform serving that subdomain. DNS alone usually cannot redirect a browser because DNS records only point hostnames toward servers; they do not return HTTP redirect responses.
This article explains the most reliable methods for Apache, Nginx, cPanel, Cloudflare, WordPress, and other common setups. You will also learn how to redirect an entire subdomain, preserve URL paths and query strings, avoid redirect loops, handle HTTPS correctly, and verify that search engines receive the intended status code. By the end, you should be able to choose and implement the method that fits your hosting environment.
What a Subdomain Redirect Actually Does
A subdomain redirect returns an HTTP response telling the visitor’s browser to request a different URL. For example, a request for blog.example.com/article-one might receive a 301 response pointing to example.com/blog/article-one. The browser then loads the destination.
This differs from forwarding traffic internally with a reverse proxy. A redirect changes the address displayed in the browser, while a proxy can serve content from another system without changing the visible URL. For most domain migrations and canonical URL changes, an HTTP redirect is the appropriate choice.
Redirects can apply to a single page, a group of paths, or every URL under a subdomain. A well-planned rule should account for more than the hostname. It may need to retain the original path, query parameters, protocol, or selected URL mappings.
DNS, HTTP Redirects, and Domain Forwarding
DNS determines where requests are sent. An A record points a hostname to an IPv4 address, an AAAA record points it to an IPv6 address, and a CNAME aliases it to another hostname. None of these records instructs a browser to replace one URL with another.
An HTTP redirect happens after the request reaches a web server or edge service. That system responds with a status code such as 301 or 302 and supplies the new URL in the Location header. Hosting companies sometimes call this feature domain forwarding, URL forwarding, or web forwarding.
A CNAME from blog.example.com to example.com does not automatically redirect visitors to the root domain. It merely directs the subdomain toward the same destination at the DNS layer. The receiving server must still recognize blog.example.com and return the redirect.
Before changing anything, confirm the following:
- The source subdomain exists in DNS and resolves to the correct server or redirect service.
- The source can accept both HTTP and HTTPS requests.
- A valid SSL certificate covers the subdomain.
- The destination URL is active and returns the intended content.
- You know whether paths and query strings should be preserved.
- You have access to the hosting panel, server configuration, application, or edge platform handling requests.
Choosing the Right Redirect Status Code
A 301 Moved Permanently response is normally the right choice when the subdomain has been retired or its content has moved for good. It signals that browsers and search engines should use the destination URL instead. Search engines may transfer ranking signals after they process the redirect.
A 302 Found response is better for temporary changes. It tells clients that the original URL may return, so they should not treat the destination as its permanent replacement. Depending on the application, 307 and 308 responses provide similar temporary and permanent behavior while explicitly preserving the request method.
For ordinary public pages requested with GET, a 301 is widely supported and usually sufficient. Redirecting forms, APIs, uploads, or other non-GET requests requires more care. A 308 preserves the method and request body, while some clients may convert a POST request into GET after a 301 or 302.
Redirect code | Meaning | Typical use
301 | Permanent move | Retired subdomain or permanent site migration
302 | Temporary move | Short-term campaign, maintenance, or testing
307 | Temporary, method preserved | Temporary API or application redirect
308 | Permanent, method preserved | Permanent API move or strict method retention
Choose the status based on the real duration of the change, not merely convenience. Avoid switching repeatedly between permanent destinations because browsers and intermediary caches may retain permanent redirects longer than expected.
Planning the Redirect Before Changing the Server
First decide whether every old URL has a meaningful equivalent. A one-to-one migration should preserve paths, sending support.example.com/install to example.com/support/install. When the new site uses a different structure, create explicit mappings for important pages instead of forcing every request to one location.
Redirecting all old URLs to the homepage is rarely useful. Visitors lose the context of the link they followed, and search engines may treat irrelevant homepage redirects as soft 404 responses. A relevant replacement page is preferable; if no replacement exists, returning 404 or 410 may be more honest.
Create a list of the subdomain’s most important URLs using analytics, search performance data, server logs, backlinks, and an XML sitemap. Map each URL to the closest destination. This is also a useful point to review your [Internal Link: Website Migration Checklist] before changing a live site.
You should also define what happens to query strings. Tracking parameters may be safe to retain, but old application parameters might be irrelevant or unsafe on the new site. Test representative URLs such as:
- http://blog.example.com/
- https://blog.example.com/article-one
- https://blog.example.com/category/news/
- https://blog.example.com/search?q=hosting
- https://blog.example.com/article-one?utm_source=newsletter
Redirecting a Subdomain with Apache
Apache redirects can be configured in the virtual host file or an .htaccess file. The virtual host configuration is generally preferable because it is processed more efficiently and is easier to control. Shared hosting customers often have access only to .htaccess.
Using Apache VirtualHost Configuration
Create separate virtual hosts for HTTP and HTTPS traffic, then return a permanent redirect to the destination. A simple HTTP configuration looks like this:
<VirtualHost *:80>
ServerName blog.example.com
Redirect permanent / https://example.com/blog/
</VirtualHost>
Apache’s Redirect directive appends the unmatched path in many common configurations. Always test the exact result because a destination subdirectory and slash handling can produce an unexpected URL structure.
For more control, use mod_rewrite:
<VirtualHost *:80>
ServerName blog.example.com
RewriteEngine On
RewriteRule ^/(.*)$ https://example.com/blog/$1 [R=301,L]
</VirtualHost>
The HTTPS virtual host needs an equivalent redirect and a certificate valid for blog.example.com:
<VirtualHost *:443>
ServerName blog.example.com
SSLEngine On
SSLCertificateFile /path/to/fullchain.pem
SSLCertificateKeyFile /path/to/privkey.pem
RewriteEngine On
RewriteRule ^/(.*)$ https://example.com/blog/$1 [R=301,L]
</VirtualHost>
After editing the configuration, validate it with the command appropriate for your system, such as apachectl configtest, before reloading Apache. A syntax check reduces the chance of taking other virtual hosts offline.
Using an .htaccess File
Place the rule in the document root assigned to the subdomain. Check the requested hostname so that the rule does not affect another site sharing the same directory:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/blog/$1 [R=301,L]
In .htaccess context, the path matched by RewriteRule normally has its leading slash removed. That is why the pattern begins with ^ rather than ^/. Query strings are retained by default when the replacement does not define a new query string.
If both www-style variants or multiple subdomains should redirect, list them deliberately rather than using an overly broad regular expression. Broad hostname patterns can capture development, staging, or customer-specific subdomains unintentionally.
Redirecting a Subdomain with Nginx
Nginx can handle a subdomain redirect with a small server block. For HTTP traffic, use return rather than a rewrite rule when possible because it is direct and easy to read:
server {
listen 80;
listen [::]:80;
server_name blog.example.com;
return 301 https://example.com/blog$request_uri;
}
The $request_uri variable contains the original path and query string. A request for blog.example.com/post?id=25 therefore redirects to example.com/blog/post?id=25.
HTTPS requires another server block with the certificate
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name blog.example.com;
ssl_certificate /path/to/fullchain.pem;
ssl_certificate_key /path/to/privkey.pem;
return 301 https://example.com/blog$request_uri;
}
Test the Nginx configuration before reloading it. On many systems, nginx -t performs the validation. Be careful with slash placement: combining a destination ending in a slash with a request URI beginning in a slash can create a double slash.
A safe Nginx implementation follows these steps:
1. Confirm that blog.example.com resolves to the Nginx server.
2. Add the HTTP server block for the source hostname.
3. Add an HTTPS server block and valid certificate.
4. Build the destination with the correct path structure.
5. Run nginx -t to check the syntax.
6. Reload Nginx without stopping active connections.
7. Test the homepage, a nested path, and a URL containing query parameters.
8. Inspect the response headers to confirm the status and Location value.
Using cPanel or Another Hosting Control Panel
Many shared hosts provide a Redirects feature in cPanel. Select the permanent redirect type, choose the source subdomain, enter the destination URL, and decide whether the rule should affect all paths. The interface often writes the corresponding Apache rule into an .htaccess file.
After saving, inspect the generated result. Control panels can create broad rules, add unwanted www conditions, or place directives below an existing rule that runs first. Test the redirect in a private browsing window and with a header-checking tool rather than assuming the panel configured it correctly.
Some hosts offer domain forwarding through their DNS or domain-management interface. Despite its location in the dashboard, this feature normally works by pointing the hostname to the provider’s web forwarding service. Confirm whether it supports HTTPS, path forwarding, query strings, and a true 301 response.
Avoid masked forwarding or framed forwarding. It keeps the source address visible by placing the destination inside a frame, which can create usability, accessibility, analytics, and indexing problems. Standard unmasked forwarding is the cleaner option.
Setting Up a Cloudflare Subdomain Redirect
When the source hostname is proxied through Cloudflare, redirects can run at the edge before a request reaches the origin server. Create a Redirect Rule that matches the hostname, such as blog.example.com, and define a static or dynamic destination.
A dynamic rule can preserve the original path and query string, while a static redirect works well when every request should go to one exact URL. Select 301 for a permanent move. Cloudflare’s interface and plan limits can change, so use the redirect-rule options shown in your current dashboard.
The DNS record for the source subdomain must generally be proxied for Cloudflare’s HTTP redirect features to process the request. Cloudflare must also be able to serve a valid certificate for the hostname. If the record is DNS-only, requests go directly to the origin, where the redirect must be configured instead.
Practical Cloudflare checklist:
□ The source hostname has an active DNS record.
□ Proxying is enabled for the record when required by the rule.
□ The rule matches only the intended hostname.
□ The destination uses HTTPS.
□ Paths are either preserved or mapped intentionally.
□ Query-string behavior has been tested.
□ The response contains one redirect, not a chain.
□ The origin does not send traffic back to the source hostname.
Handling Redirects in WordPress
A WordPress redirect plugin can redirect pages or patterns, but a server-level rule is usually better for retiring an entire subdomain. It works before WordPress, PHP, the theme, and plugins load, reducing overhead and avoiding dependency on the application.
A plugin remains useful when editors need to maintain individual URL mappings or when server access is unavailable. Make sure WordPress is still reachable on the source subdomain, and verify that the plugin can match the hostname as well as the path.
Changing the WordPress Address or Site Address is not the same as configuring a complete migration redirect. Those settings control where WordPress considers itself installed. Existing requests to the old hostname still need to reach a service capable of returning a redirect.
When moving a WordPress site from blog.example.com to example.com/blog, update internal links, canonical tags, media URLs, sitemaps, and application settings as needed. Database URL replacement should use a method that safely handles serialized data. You may also find this [Internal Link: WordPress URL Change Guide] useful during the migration.
Preserving Paths and Query Strings
Path preservation is appropriate when the old and new
blog.example.com/guides/ssl
→ example.com/blog/guides/ssl
Dropping the path would send every visitor to example.com/blog, even when a more relevant page exists. This weakens the user experience and makes it harder for search engines to associate old content with its replacement.
A structural migration may require custom mappings instead:
help.example.com/getting-started/install
→ example.com/docs/installation
help.example.com/account/reset
→ example.com/support/password-reset
Create exact redirects for high-value pages first, followed by broader fallback rules. Exact rules must be evaluated before catch-all rules, or the general redirect will intercept the request.
Query parameters require similar judgment. Most common Apache and Nginx examples retain the original query string automatically, but platform behavior varies. Confirm it by testing an actual parameter rather than relying solely on the configuration’s appearance.
Do preserve:
- Paths that have matching content at the destination.
- Useful tracking parameters required for campaign attribution.
- Functional parameters supported by the new application.
Do not preserve:
- Obsolete parameters that produce errors or irrelevant results.
- Sensitive values that should not be copied to another domain or service.
- Old routing parameters when clean destination URLs already exist.
- Every URL path when the destination has a completely different structure.
HTTPS and SSL Certificate Requirements
A redirect from an HTTPS URL occurs only after a secure connection has been established. The source subdomain therefore needs a valid SSL certificate even when it returns no content other than a redirect. Without one, visitors see a certificate warning before the server can send the new location.
The certificate may cover the exact hostname, such as blog.example.com, or use a suitable wildcard such as *.example.com. A typical wildcard does not cover deeper names such as news.blog.example.com, and it does not necessarily cover the bare example.com domain.
Keep the source certificate active for as long as old HTTPS links may receive traffic. Removing the hosting account, DNS record, or certificate immediately after migration breaks the redirect. Search engines and users need continued access to the source in order to receive the 301 response.
For best results, redirect directly from the old HTTPS URL to the final HTTPS destination. Avoid an HTTP-to-HTTPS step followed by a hostname redirect when one response can reach the final address.
Testing the Redirect Correctly
A browser confirms that navigation works, but it may hide useful details and cache permanent redirects. Use an HTTP header tool or curl to inspect the response directly:
curl -I https://blog.example.com/example-page?ref=test
The output should contain the intended status, such as HTTP/2 301, and a Location header with the final destination. Repeat the test for HTTP, HTTPS, nested paths, trailing slashes, uppercase characters where relevant, and query strings.
To follow the entire chain, use:
curl -IL https://blog.example.com/example-page
Ideally, the request should reach the final page through a single redirect. The destination should return a successful status, commonly 200, and should not redirect back to the source or pass through several intermediate URLs.
Test from a private window or clear browser redirect caches when results appear inconsistent. Also check from outside your local network if DNS has recently changed. Local DNS caches, hosts-file entries, VPNs, and corporate proxies can produce results that differ from what public visitors receive.
Common Redirect Problems and Their Fixes
Redirect loops occur when the source sends visitors to the destination but another rule sends them back. They can also appear when a reverse proxy and origin disagree about whether the original request used HTTPS. Review every layer that can issue redirects, including the CDN, load balancer, web server, application, and plugins.
A redirect chain occurs when one URL passes through multiple steps, such as HTTP to HTTPS, then the subdomain to the root domain, then a trailing-slash correction. Consolidate these rules so each source variant points directly to the final canonical URL where possible.
Common mistakes include:
- Replacing a DNS record and expecting the browser address to change.
- Deleting the source subdomain before installing the redirect.
- Forgetting to issue or renew the source SSL certificate.
- Sending every old page to an unrelated homepage.
- Matching all subdomains with an overly broad wildcard rule.
- Adding a destination URL that redirects back to the source.
- Creating double slashes when joining a destination path and request URI.
- Testing only the homepage and missing broken nested paths.
- Using a 302 for a migration intended to remain permanent.
- Leaving internal links pointed at the old subdomain indefinitely.
A redirect that works over HTTP but fails over HTTPS almost always indicates a missing HTTPS listener, certificate, or secure virtual host. A 404 response usually means the request reached a server that does not recognize the hostname or that another route handled it before the redirect rule.
SEO Considerations After Moving a Subdomain
Keep permanent redirects active for a substantial period. Old links, bookmarks, cached search results, and external references may continue sending visitors to the subdomain long after the migration. In many cases, maintaining the redirects indefinitely is practical and beneficial.
Update internal links so visitors do not depend on redirects during normal navigation. Also revise canonical tags, hreflang annotations, XML sitemaps, structured data, social profile links, advertising destinations, email templates, and third-party integrations that reference the old hostname.
Submit or refresh the destination sitemap in the relevant search engine tools, then monitor indexing, crawl errors, traffic, and server logs. A short period of fluctuation can occur during a move, but persistent losses may indicate missing redirects, irrelevant mappings, blocked crawling, incorrect canonicals, or inaccessible destination pages.
Do not block the old subdomain in robots.txt before search engines can crawl its redirects. A crawler needs to request the old URL to see the 301 response. Likewise, do not protect the source with a login prompt if public URLs are supposed to transfer their signals.
When a Redirect Is Not the Right Solution
A reverse proxy is more suitable when the subdomain must remain visible while content is served from another application or server. For example, docs.example.com can display content hosted by a documentation platform without changing the public URL, provided the platform supports that arrangement.
DNS changes are appropriate when the hostname should continue working exactly as entered but needs to point to new infrastructure. In that case, use an A, AAAA, or CNAME record and configure the destination server to accept the hostname. No browser-visible redirect is required.
URL rewriting may be preferable when only the internal routing should change. A rewrite lets the server locate different content while leaving the requested address intact. Because redirects and rewrites solve different problems, confirm whether the visitor should see the new URL before choosing a method.
Application-level routing can make sense when the destination depends on account data, authentication, language, geography, or database-managed mappings. Keep simple hostname migrations at the server or edge whenever possible, where they remain fast and independent of application availability.
Conclusion
A reliable subdomain redirect requires more than changing a DNS record. The source hostname must continue resolving to a service that can accept the request, establish HTTPS when necessary, and return an HTTP redirect to the correct destination. For a permanent migration, that usually means a 301 response configured in Apache, Nginx, a hosting panel, or an edge platform such as Cloudflare.
The most important decisions concern URL mapping. Preserve paths when the old and new structures align, create exact mappings when they do not, and avoid sending unrelated pages to the homepage. Test HTTP and HTTPS versions, nested paths, trailing slashes, and query strings before considering the work complete.
Once you know how to redirect subdomain traffic correctly, update internal links and other URL references so normal visits go directly to the new location. Keep the source DNS, SSL certificate, and redirect service active while old links remain in use. A direct, relevant, single-hop redirect gives visitors a predictable result and helps search engines process the move efficiently.
Frequently Asked Questions
Can DNS redirect a subdomain to a URL?
No. DNS can point a subdomain to an IP address or hostname, but it cannot return a URL path or HTTP redirect. A web server, forwarding service, CDN, or edge rule must issue the redirect response.
Should I use a 301 or 302 redirect?
Use a 301 when the subdomain has moved permanently. Choose a 302 when the change is genuinely temporary and the original address will return. API redirects may require 307 or 308 to preserve request methods.
Can a subdomain redirect preserve page paths?
Yes. Apache, Nginx, Cloudflare, and many hosting panels can append the original request path to the destination. Test nested pages and query strings carefully because slash handling and parameter behavior vary between configurations.
Does the old subdomain still need an SSL certificate?
Yes, if visitors may request it over HTTPS. The secure connection is established before the redirect response is delivered. Without a valid certificate, users may receive a security warning instead of reaching the destination.
How long should a subdomain redirect remain active?
Keep a permanent redirect active for at least as long as old links, bookmarks, and indexed URLs receive traffic. Maintaining it indefinitely is often the safest option when the old hostname will never be reused.