/ โ† Redirect Fixes / 301 redirect a domain
In this guide
  1. What a domain-wide 301 redirect does
  2. Why domain redirects break, and why SSL errors appear
  3. How to test what the old domain returns
  4. Server rules that keep the path
  5. Registrars, Cloudflare and Plesk
  6. A worked example
  7. The fix, step by step
  8. Edge cases worth knowing
  9. Keeping the redirect healthy
  10. Questions and answers

What a domain-wide 301 redirect does

A 301 redirect is an HTTP response that says a resource has moved permanently. When you redirect a whole domain, every request to the old hostname gets a 301 response with a Location header pointing at the matching address on the new domain. Browsers follow it automatically, and search engines treat it as a strong signal that the new URL should replace the old one in their index.

The important word is matching. A good domain redirect keeps the path and the query string, so https://old-example.com/menu/cakes?size=large goes to https://example.com/menu/cakes?size=large, not to the new home page. Sending everything to the home page throws away the relevance of each old page, and Google tends to treat mass redirects to an unrelated page as soft 404s, so the old pages simply drop out rather than passing their signals on.

Status codeMeaningUse it for a domain move?
301 Moved PermanentlyPermanent move; clients may change POST to GETYes, the standard choice
308 Permanent RedirectPermanent move; method and body keptYes, equally fine for Google
302 Found / 307 TemporaryTemporary moveNo, the old URLs tend to stay indexed
Meta refresh or JavaScriptRedirect done in the pageOnly as a last resort
Frame or masked forwardingNew site shown inside the old addressNo, it is not a redirect at all

Google treats 301 and 308 the same way for indexing. What matters more is that the redirect is permanent, happens in one hop, and answers correctly on every version of the old hostname: http and https, with and without www.

Why domain redirects break, and why SSL errors appear

Most failed domain moves come down to one of a handful of causes:

SymptomUsual cause
Browser shows a certificate or privacy warning on the old domainThe old hostname has no valid certificate, or the server sends a certificate for a different name
Every old URL lands on the new home pageThe rule redirects to a fixed address instead of carrying the path
Redirect works on http but not on httpsRegistrar forwarding or a parking server only listens on port 80
Status shows 302 instead of 301Forwarding set to temporary, or the default of a plugin or control panel
Two or three hops before the final pageSeparate rules for http to https, www and the domain change, run one after another
Address bar still shows the old domainMasked or framed forwarding is switched on

Why the certificate matters before the redirect

This is the part that catches most people out. When a visitor types or clicks https://old-example.com, the browser first opens a TLS connection to that hostname and checks the certificate. Only after the handshake succeeds does it send the HTTP request and receive your 301. If the certificate is missing, expired, or issued for another name, the browser stops at a warning page and never sees the redirect. So a domain you are moving away from still needs a valid certificate for as long as you keep the redirect running, which should be at least a year.

Registrar forwarding services differ here. Some issue a certificate for the forwarded domain automatically, some take a while to do so, and some only forward plain http. If you test the https version of the old domain and get a warning, that is the reason. The fix is to point the old domain at a server or service that holds a valid certificate for it, as covered below. Our SSL hostname mismatch guide explains the certificate side in more depth.

How to test what the old domain returns

Do not trust the browser alone: it caches 301 responses aggressively, so you may be looking at an old result. Use curl from a terminal, which shows every hop and status code:

curl -sI http://old-example.com/menu/cakes
curl -sI https://old-example.com/menu/cakes
curl -sI https://www.old-example.com/menu/cakes?size=large

# follow the whole chain and print each status and location
curl -sIL https://old-example.com/menu/cakes | grep -iE '^(HTTP|location)'

For each variant you want to see a single HTTP/1.1 301 or HTTP/2 301 line, a location: header with the full new address including the path, and then a 200 from the new domain. If curl reports an SSL error such as SSL: no alternative certificate subject name matches, the certificate problem is confirmed.

To see which names the certificate actually covers, run:

openssl s_client -connect old-example.com:443 -servername old-example.com </dev/null 2>/dev/null \
  | openssl x509 -noout -subject -ext subjectAltName -dates

Both old-example.com and www.old-example.com should appear in the subject alternative names, and the notAfter date should be in the future. The redirect checker demo shows the same hop-by-hop view without a terminal.

Server rules that keep the path

The most reliable setup is to keep the old domain pointed at a web server you control, with a certificate for it, and a single rule that sends everything to the new domain.

Apache (.htaccess in the old domain's document root)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?old-example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

The query string is carried over automatically. Put this above any other rewrite rules, such as those from WordPress, so it runs first.

nginx

server {
    listen 80;
    listen 443 ssl;
    http2 on;
    server_name old-example.com www.old-example.com;

    ssl_certificate     /etc/letsencrypt/live/old-example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/old-example.com/privkey.pem;

    return 301 https://example.com$request_uri;
}

$request_uri holds the original path and query string, so nothing is lost. On older nginx versions, write listen 443 ssl http2; instead of the separate http2 on; line. Get the certificate first, for example with sudo certbot certonly --nginx -d old-example.com -d www.old-example.com, then run sudo nginx -t and sudo systemctl reload nginx.

One hop, not three

Send every variant of the old domain straight to the final https address on the new domain. Avoid a chain such as http old, then https old, then https new, then https www new. The redirect chains guide shows how to collapse chains that build up this way.

Registrars, Cloudflare and Plesk

โš ๏ธ Do not let the old domain expire or drop its DNS after the move. Once it stops answering, every backlink to it stops passing anything, and someone else can register it and use your old links.

A worked example

Example Bakery is moving from old-example.com to example.com. The old domain is registered at one registrar with web forwarding set to the new home page. Testing gives this:

$ curl -sI http://old-example.com/menu/cakes
HTTP/1.1 302 Found
Location: https://example.com/

$ curl -sI https://old-example.com/menu/cakes
curl: (60) SSL: no alternative certificate subject name matches target host name 'old-example.com'

Three problems show up at once: a temporary status, a lost path, and no certificate on https. The bakery switches the old domain's nameservers to its own server, issues a certificate for both names, and adds the nginx block from above. The retest:

$ curl -sI https://old-example.com/menu/cakes
HTTP/2 301
location: https://example.com/menu/cakes

Then it uses the Change of Address tool in Search Console, under the old property's settings, to tell Google about the move, and updates its own internal links and sitemap so they point directly at example.com.

The fix, step by step

Step 1

List every version of the old domain

Write down the four starting points that must redirect: http and https, each with and without www, for the old domain. Add any other domains or subdomains you have used for the site, such as shop or blog. Pick a handful of real deep URLs from your analytics or sitemap to test with, including one with a query string. Every one of these must reach the matching page on the new domain in a single 301 hop.

Step 2

Point the old domain at something you control

Decide where the old domain will be answered: your own web server, Plesk, or Cloudflare. Update its DNS records or nameservers at the registrar so the root and www point there. Avoid relying on registrar forwarding unless you have tested that it covers https and keeps paths. Wait for DNS to update, then confirm with dig +short old-example.com that the records point to the server or service you chose.

Step 3

Issue a certificate for the old names

Get a valid certificate covering both old-example.com and www.old-example.com on the server that will answer them. On a plain server use sudo certbot certonly --nginx -d old-example.com -d www.old-example.com; in Plesk use the Let's Encrypt option under SSL/TLS Certificates; on Cloudflare the edge certificate is issued once the records are proxied. Confirm with the openssl command that both names appear and the expiry date is in the future.

Step 4

Add one rule that keeps the path

Add a single permanent redirect for the old hostnames that sends each request to https://example.com plus the original path and query string. In nginx use return 301 https://example.com$request_uri;, in Apache a RewriteRule with R=301, and in Cloudflare a dynamic redirect with preserve query string ticked. Place it before any other rules. Reload the server after running sudo nginx -t or apachectl configtest to catch typing mistakes.

Step 5

Map any changed URLs first

If some pages have new paths on the new domain, add specific redirects for those above the catch-all rule, so each old page goes to its true replacement rather than to a missing page. Use a map file or a list of rules exported from a spreadsheet of old and new URLs. Test a sample from the list and make sure none of the targets returns a 404 or redirects again.

Step 6

Test every variant with curl

Run curl -sIL against each of the four starting versions and your sample deep URLs. Each should show one 301 with a location header that contains the full new address, followed by a 200. There should be no certificate errors, no 302, and no second hop. If anything is wrong, fix the rule and retest before going further, because browsers cache permanent redirects.

Step 7

Tell Google with Change of Address

Verify both the old and new domains in Search Console if you have not already. In the old property, open Settings and then Change of Address, choose the new property and submit. The tool checks that the home page redirects correctly. Submit the new sitemap in the new property, and keep the old sitemap available for a while so Google recrawls the old URLs and sees the redirects.

Step 8

Update links and keep it running

Change internal links, canonical tags, sitemaps and hreflang on the new site so they use the new domain directly rather than relying on the redirect. Update the links you control elsewhere, such as social profiles and business listings. Keep the old domain registered, its certificate renewing and the redirect live for at least a year, and recheck the curl tests after any hosting or DNS change.

Edge cases worth knowing

Keeping the redirect healthy

Keep the redirect and the old domain's registration and certificate in place for at least a year, and longer if the old domain has many backlinks. Set renewal reminders for both. Re-run the curl tests after any server, DNS or hosting change, and check the Page with redirect report in Search Console for the old property, which should fill with old URLs as Google processes the move. If you see a redirect error there, the redirect error guide explains what each message means. For a site move that also changes structure, follow the migration redirects guide.

Questions and answers

1. How do I 301 redirect a domain to another domain?

Point the old domain at a server or service you control, give it a valid certificate, and add one permanent rule that sends every request to the same path on the new domain. In nginx that is a server block with return 301 to the new domain plus the request URI. In Apache it is a RewriteRule with the R=301 flag. Cloudflare and Plesk offer the same through their redirect settings. Then test every version of the old domain and use Change of Address in Search Console.

2. Why do I get an SSL certificate error when my 301 redirect runs?

The browser checks the certificate for the old domain before it ever receives the redirect, so a missing or wrong certificate stops the visitor at a warning page. This often happens when the old domain is parked, forwarded by a registrar that only handles http, or served by a server whose certificate names a different domain. The fix is to issue a certificate covering both the root and www of the old domain on whatever answers it, and keep it renewing for as long as the redirect stays.

3. Can I use GoDaddy or Network Solutions forwarding for a 301 redirect?

You can, as long as you choose a permanent 301 forward without masking, and you test the result afterwards. Registrar forwarding is convenient for a simple domain, but services differ in whether they keep the path and whether they serve a valid certificate on https. Run curl against both the http and https versions of the old domain with a deep URL. If the path is lost or https shows a certificate error, move the old domain to your own server or Cloudflare instead.

4. Should I redirect all old pages to the new home page?

No. Redirect each old URL to its closest equivalent on the new domain, which for a straight domain move is the same path. Sending everything to the home page loses the relevance of each page, frustrates visitors who followed a specific link, and Google may treat those redirects as soft 404s, so the old pages pass little or nothing to the new site. Only send a page to the home page if nothing on the new site genuinely replaces it.

5. How long should I keep a domain 301 redirect in place?

Keep it for at least a year, and ideally for as long as the old domain has backlinks or visitors arriving from bookmarks, emails and printed material. Google recommends keeping redirects for at least a year after a site move so it can process every old URL. In practice many businesses keep the old domain and its redirect running indefinitely, because the cost of renewing a domain and a free certificate is small compared with losing old links.

6. Is a 308 redirect better than a 301 for a domain move?

For search engines they behave the same: both are permanent and Google treats them as equivalent for passing signals. The difference is for form submissions, because a 308 keeps the request method and body while a 301 allows clients to switch a POST to a GET. For a website domain move, a 301 is the familiar choice and works everywhere. Use a 308 if old forms or API calls might still post to the old domain.

7. Do I need hosting on the old domain to redirect it?

You need something that answers requests for the old domain, but it does not have to be a full hosting plan. A small server block on your existing server, a domain alias in Plesk, or the old domain added to Cloudflare with a redirect rule all work without hosting any content. What you do need is a valid certificate for the old names on that service, and DNS for the old domain pointing to it.

Check your domain redirect hop by hop

The redirect checker follows each version of your old domain, shows every status code and location, and flags chains, temporary redirects and certificate failures before Google finds them.

Open Redirect Fixes โ†’
๐Ÿ’ฌ Got a problem?
Related Guides: All Redirect Fixes  ·  Set Up a 301 Redirect  ·  301 Redirect Not Working  ·  HTTPS Redirects  ·  Migration Redirects  ·  Learning Hub

About aiwebpageseo

aiwebpageseo.com is a data-driven SEO and AEO (Answer Engine Optimisation) platform providing a free suite of technical SEO tools. Rather than relying on AI-theorised assumptions, the platform analyses live URL performance, delivering objective diagnostics, page speed metrics, CLS debugging, and site crawl data alongside actionable technical tutorials.