Skip to content

SEOPart of: Redirects

How to redirect a domain to another domain, path by path

Redirect a whole domain, or an extra or old domain, to another one with a 301 that keeps every path and query string. Setups for Cloudflare, Apache, nginx, cPanel and registrar forwarding, and how to test them.

getReport teamUpdated 26 Sept 202611 min read

To redirect a domain to another domain, answer every request on the old domain with a 301 to the same path on the new one: old-example.com/shop/mugs?color=blue should go to https://www.new-example.com/shop/mugs?color=blue in a single hop, over http and https, with and without www. You can set that up at a CDN such as Cloudflare, on the web server, in a hosting control panel or with your registrar's forwarding, as long as the method keeps the path and supports https. This guide gives the setup for each, the cases where the path should change, and how to test the result. For what a 301 does and why it keeps rankings, see the 301 redirects guide.

Quick answer

  • Redirect path to path, not everything to the new home page. Deep pages keep their links and rankings only if each one lands on its equivalent.
  • One hop, permanent. A 301 (or 308) straight to the final https address, not http → https → www → new domain.
  • Keep the query string. Campaign links and old parameter URLs depend on it.
  • Cover every variant of the old domain: http and https, with and without www, and any subdomains you used.
  • The old domain needs a valid certificate, or https visitors see a security warning before any redirect happens.
  • Keep the old domain registered and redirecting for years, not months.
  • Test several deep URLs with the redirect checker, not only the home page.

When you need a domain redirect

The same technique covers four situations, with one difference in what each old URL should point to:

SituationWhere old URLs should go
Moving the whole site to a new domain with the same URLsSame path on the new domain
Moving to a new domain and changing URLs at the same timeEach old URL to its final new URL, from a redirect map
An extra domain you own, such as a typo, old brand or other extensionSame path on the main domain, or the home page if it never had pages
Merging another site into yoursEach page to its closest equivalent on your site

A domain that simply serves the same site as your main one, without redirecting, is the case to avoid: search engines see two copies of every page. Redirect it.

For a full move of a site that ranks, the redirect is only one part. Changing domain name without losing SEO covers the rest: the Change of Address tool in Search Console, updating canonicals, sitemaps and links, and what to expect afterwards. When URLs change as well, build the list first with the redirect mapping guide.

Before you start: DNS and certificates

A redirect can only answer a request that reaches something. For the old domain:

  1. Keep the domain registered and set to renew. If it lapses, someone else can buy it, along with its links.
  2. Point its DNS at whatever will answer the redirect: your CDN, your web server or the registrar's forwarding service. Include both old-example.com and www.old-example.com.
  3. Make sure https works on the old domain. Browsers connect over https first for most links and bookmarks. Without a certificate for the old domain, visitors get a certificate error and never see the redirect. CDNs and many hosts issue one automatically; a server needs one like any other site, for example from Let's Encrypt.
  4. Leave the email records alone. Changing where the web traffic goes does not require touching the MX, SPF or DKIM records. If you move the DNS to a new provider, copy those records across first, or email for the old domain stops.

How to redirect a domain with Cloudflare

If the old domain is on Cloudflare, the redirect answers at the edge, with no server behind it.

  1. Add the old domain to Cloudflare and point its nameservers there.
  2. Make sure the hostnames you redirect have proxied DNS records (orange cloud). Cloudflare's redirect rules only see proxied traffic; when you create a rule for a hostname without one, the dashboard offers to create a proxied record for you.
  3. Go to Rules → Redirect Rules and create a rule. Cloudflare's own example for redirecting one domain to another uses a wildcard pattern:
    • Request URL: http*://old-example.com/*
    • Target URL: https://www.new-example.com/${2}
    • Status code: 301
    • Preserve query string: on
  4. Create a second rule, or widen the pattern, for www.old-example.com.

${2} is the path matched by the second *, so https://old-example.com/shop/mugs goes to https://www.new-example.com/shop/mugs. Cloudflare issues a certificate for proxied hostnames automatically. For a list of individual URLs, Bulk Redirects take a CSV; the setup guide for Apache, nginx, Cloudflare and WordPress shows both.

How to redirect a domain on Apache

If the old domain still points at an Apache or LiteSpeed server, add this at the top of the .htaccess file in the old domain's document root, or in its virtual host:

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

$1 carries the path, and mod_rewrite passes the original query string along unchanged when the target has none of its own. The RewriteCond matters when both domains point at the same folder: without it, the rule would also redirect the new domain to itself, in a loop.

How to redirect a domain on nginx

Give the old domain its own server block that does nothing but redirect:

nginx
server {
    listen 80;
    listen 443 ssl;
    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://www.new-example.com$request_uri;
}

$request_uri includes the path and the query string, so nothing is lost. Reload nginx after checking the configuration with nginx -t.

How to redirect a domain in cPanel or your host's panel

Most shared hosts let you set this up without editing files. In cPanel, open Domains → Redirects:

  1. Type: Permanent (301).
  2. Domain: the old domain. Choose the option that covers it with and without www.
  3. Redirects to: https://www.new-example.com/.
  4. Tick Wild Card Redirect, which sends each path to the same path on the target instead of everything to the home page.

cPanel writes the rule into .htaccess for you. Other panels, such as Plesk, have similar settings; look for a permanent redirect that keeps the path.

Registrar domain forwarding

Registrars offer "domain forwarding" or "URL forwarding" for domains without hosting. It is fine for a typo domain that never had pages, but check three things before relying on it for a domain that did:

  • Does it keep the path? Some services send every URL to the one address you enter. Look for an option such as "forward path" or "wildcard".
  • Does it work over https? Some forward only http:// requests, and https visitors see an error.
  • Is it a 301? Some use a 302 by default, and some use "masking", which shows the new site inside a frame on the old address. Masking is not a redirect at all; avoid it.

If any answer is no, move the domain's DNS to a CDN or host that does all three.

Other platforms

Netlify: add the old domain as a domain alias to the same site, then a _redirects rule such as https://old-example.com/* https://www.new-example.com/:splat 301!.

Vercel: add the old domain to the project and set it to redirect to the main domain in the project's domain settings, choosing a permanent status.

Hosted website builders: most let you connect an extra domain and mark one as primary, redirecting the others. Check the status code and that deep paths survive.

Pointing old URLs straight at their final address

If URLs changed on the new domain too, a same-path rule creates a chain: old domain → same path on the new domain → the new URL. Redirect those old URLs directly to their final targets, and keep the same-path rule only as a fallback for everything else. In a CDN or server, put the specific rules first.

The generator writes exact-match rules from a list of old and new URLs, for Apache, nginx, Cloudflare Bulk Redirects, Netlify, Vercel or Caddy, and points chains in your list straight at their final page:

How to test a domain redirect

Enter a deep URL on the old domain, not only the home page. The checker follows every hop to the page that answers, lists each status code, and also requests the http and the other www variant of the address to see whether they redirect permanently. You want exactly one 301 or 308 from any old variant, then a 200 on the matching page of the new domain, whose canonical is its own address.

Test at least these, replacing the path with a real one from your site:

  • http://old-example.com/a-deep-page/
  • https://old-example.com/a-deep-page/?utm_source=test
  • https://www.old-example.com/a-deep-page/

For a full list of old URLs, such as your old sitemap, paste them into the bulk URL checker, or old and new pairs into the migration redirect validator, which gives each pair a verdict. The full getReport report on the new domain checks that its own http and www variants redirect in one hop:

Common mistakes

  • Everything to the new home page. Google may treat mass redirects to an unrelated page like missing pages, and visitors lose what they came for.
  • Forgetting https or www on the old domain. One variant redirects, another shows an error.
  • Chains through the new domain's own rules, such as old → http://new-example.com → https://new-example.com → https://www.new-example.com. Target the final form directly.
  • Frame "masking" instead of a redirect. Search engines see the old domain with no content of its own.
  • Letting the old domain expire. Its links and traffic go to whoever buys it next.
  • Deleting MX records while moving DNS, which silently breaks email on the old domain.

Questions people ask

How do I redirect a domain to another domain?

Send every request on the old domain to the same path on the new one with a 301, keeping the query string. On Cloudflare, use a Redirect Rule with a wildcard such as http*://old-example.com/* to https://www.new-example.com/${2}; on Apache, a RewriteCond on the host plus RewriteRule ^(.*)$; on nginx, return 301 https://www.new-example.com$request_uri;.

Can a 301 redirect point to another domain?

Yes. A 301 can send a URL to any address, including a page on a different domain, which is how domain moves and site mergers work. Search engines pass the old URL's signals to the target as with any permanent redirect. Redirect each path to the matching page rather than the home page, and for a full move also use Search Console's Change of Address tool.

Can I redirect a domain without hosting?

Yes. Your registrar's domain forwarding can do it, or you can put the domain on a CDN such as Cloudflare and use a redirect rule with no server behind it. Check that the method keeps the path, works over https and uses a 301. Avoid forwarding with "masking", which frames the new site instead of redirecting.

How long should I keep a domain redirect in place?

At least a year, and ideally for as long as you own the old domain. Google's site move guidance says to keep redirects for at least one year, and its Change of Address help asks for at least 180 days. Links from other sites and bookmarks keep arriving for years, and a redirect costs almost nothing to keep.

Check your site before and after Check