Skip to content

SEOPart of: Redirects

URL forwarding: how to redirect a domain to another domain, path by path

URL forwarding done right: 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 4 Oct 202614 min read

URL forwarding, also called domain forwarding, sends everyone who visits one domain to another. To redirect a domain to another domain properly, 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, supports https and does not mask the new site in a frame. 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.
  • Registrar URL forwarding is fine if it sends a 301, keeps the path and works over https. Never use masked (framed) forwarding.
  • 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.

URL forwarding and domain forwarding at your registrar

Most registrars offer URL forwarding, also called domain forwarding, for domains without hosting: you enter a destination in the domain's settings, and the registrar's own servers answer requests for the domain. It is the quickest way to point a spare domain at your site, and for a typo or brand domain that never had pages of its own it is often all you need. For a domain that had pages, links or rankings, check how the service redirects before you rely on it.

301 forwarding vs masked forwarding

Registrars usually offer two kinds of forwarding, under different names. The plain kind is labelled something like "forward only", "unmasked" or "permanent (301)", often with a temporary 302 as a second choice. The other is labelled "forward with masking", "masked", "URL frame" or "stealth forwarding".

301 (unmasked) forwardingMasked (framed) forwarding
What the old domain answersA 301 and the new addressA 200 page that loads the new site in a frame
Address barShows the new domainShows the old domain on every page
What search engines indexThe new domain, with the old domain's signalsOne near-empty page on the old domain
Use it forEvery domain move and extra domainNothing, in practice

Why masked forwarding is bad for SEO and HTTPS

Masking is not a redirect at all. It keeps the old domain in the address bar by serving a small page whose only content is a frame holding the new site, and that causes several problems:

  • Search engines get nothing useful. The old domain serves a page with no content of its own, so there is nothing to rank there, and its links are not passed to the new domain the way a 301 passes them. Registrars' own help pages say as much: masked forwarding ranks worse than a 301 or 302, and can create duplicate content.
  • Many sites refuse to be framed. The X-Frame-Options header or the frame-ancestors rule of a Content Security Policy (both documented on MDN) tell browsers not to show a page inside another site's frame, a standard defence against clickjacking. If your site sends either, visitors to the masked domain see an empty frame or a browser error.
  • HTTPS has to work twice. The framing page on the old domain needs its own certificate, and not every forwarding service provides one, so visitors who arrive over https can get a certificate warning. If the destination is still on plain http, browsers block it inside an https page as mixed content.
  • The address never changes. Visitors cannot bookmark or share a deep page, every page shows the same URL, and the padlock they see belongs to the old domain, not the site they are typing into.
  • Logins and carts can break. To the browser the framed site is a third party. Safari and Firefox block or partition third-party cookies by default, so sign-ins, carts and consent choices inside the frame may not stick.

What to check before you use registrar forwarding

  • Is it a 301? Choose the permanent option, not a 302, and never masking.
  • Does it keep the path? Some services send every URL to the one address you enter. Look for an option such as "forward path", "wildcard" or "redirect with path".
  • Does it work over https? Some forward only http:// requests, and https visitors see a certificate error. Test https://old-example.com/ yourself.
  • Does it cover www and the bare domain? Many services need a separate entry for each.

If any answer is no, move the domain's DNS to a CDN or host that does all of it, and set up the redirect there with one of the methods above.

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 URL 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.

What is the difference between URL forwarding and a 301 redirect?

URL forwarding is the feature, usually in your registrar's settings, and a 301 redirect is one way it can work. Unmasked forwarding answers the old domain with a 301 (or a 302 if you pick temporary), which is a normal redirect. Masked forwarding answers with a page that frames the new site, which is not a redirect and passes nothing on. For SEO, pick permanent, unmasked forwarding that keeps the path.

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