Loading...

CDN.com.tr Help

Redirect a domain to another domain (301)

Send requests for a domain to another domain with a permanent (301) redirect from the Redirects tab of Delivery Rules. The path and query string are kept, and Auto SSL certificate checks under /.well-known keep working.

Redirect a domain to another domain (301)

Send requests for a domain to another domain with a permanent (301) redirect from the Redirects tab of Delivery Rules. The path and query string are kept, and Auto SSL certificate checks under /.well-known keep working.

Related guides

Why browsers remember a 301, HTTPS on the redirected domain, the HSTS step after an HTTPS redirect, and the rules a domain uses again once its redirect is gone.

Background

301 vs 302 redirect: which one to use, and the mistakes that stick

Why browsers remember a 301, redirect chains, and how to audit them with curl.

Read the guide
After an HTTPS redirect

Turn on HSTS for your hostnames

Once HTTP visitors are redirected to HTTPS, HSTS lets returning browsers skip the HTTP request.

Open the topic
Certificates

Use Auto SSL

A redirect over HTTPS needs a certificate on the redirected domain.

Open the topic
Delivery rules

Write cache behavior with Add Rule

The rules that serve a domain over the protocols it is not redirected on.

Open the topic

Panel path

  1. Management Panel
  2. Delivery Rules
  3. Redirects
  4. Domain redirects
  5. Add redirect

Prerequisites

  • The domain to redirect is served by a delivery rule of this account; for HTTPS, it also has a certificate.
  • The target domain already answers on the protocol you send visitors to.
  • The owner or editor role: viewers can see redirects but cannot change them.

Decision model

Which protocols?

For requests over decides which requests are redirected. A new redirect starts with both ticked.

  • HTTP and HTTPS: move a whole domain, such as an old brand domain, to a new one.
  • HTTP only, with https:// and the same domain under To: send HTTP visitors to HTTPS.

Which protocol on the target?

The choice under To.

  • Same protocol as the request: an HTTP request goes to http:// on the target, an HTTPS request to https://.
  • https://: every redirected request goes to HTTPS on the target.
  • http://: every redirected request goes to HTTP on the target.

Domain redirect or mobile redirect?

Both are on the Redirects tab.

  • Domain redirect: permanent (301), for the domains you tick.
  • Mobile redirect: temporary (302), for visitors on mobile browsers, on every domain of the account.

Step-by-step guide

1

Add the redirect

One redirect can cover several domains of the account.

  • Open Delivery Rules, go to Redirects and press Add redirect.
  • Tick the domains under Redirect these domains and the protocols under For requests over.
  • Under To, choose the protocol and enter the target domain, then read the Example line.
  • Press Save redirect.

Expected result: The redirect appears in the Domain redirects table with its From, Protocols and To, and the page shows Live once the edge serves it.

2

Check it from outside

Request an old URL with a path and a query string over each redirected protocol and, on a domain with Auto SSL, one path under /.well-known/ over HTTP.

  • Request the old URL over HTTP and over HTTPS.
  • Request a path under /.well-known/ on the redirected domain over HTTP (on a domain with Auto SSL).

Expected result: A 301 whose location is the target with the same path and query string; the /.well-known/ request (on a domain with Auto SSL) is answered without a redirect to the target.

cdnctl equivalent
curl -s -o /dev/null -D - 'http://old.example.com/blog/post?id=7' | grep -iE '^(HTTP|location)'
curl -s -o /dev/null -D - 'https://old.example.com/blog/post?id=7' | grep -iE '^(HTTP|location)'
curl -s -o /dev/null -w '%{http_code} %{redirect_url}\n' http://old.example.com/.well-known/acme-challenge/test
3

Change or remove it

A redirect stays until you delete it.

  • Press Edit on the redirect's row to change its domains, protocols or target, then Save redirect.
  • Press Delete, then Delete redirect to confirm.

Expected result: After a delete, the domains are served by their rules again, and the page shows Live once the edge serves the change.

Verification

  • curl -s -o /dev/null -D - 'http://old.example.com/blog/post?id=7' | grep -iE '^(HTTP|location)' → 301, location: https://new.example.com/blog/post?id=7 (with https:// under To)
  • curl -s -o /dev/null -D - 'https://old.example.com/blog/post?id=7' | grep -iE '^(HTTP|location)' → 301, location: https://new.example.com/blog/post?id=7
  • curl -s -o /dev/null -w '%{http_code} %{redirect_url}\n' http://old.example.com/.well-known/acme-challenge/test → no redirect to the target (on a domain with Auto SSL)

Use cases

A brand moves from old.example.com to new.example.com, or a site settles on one address (www.example.com rather than example.com, HTTPS rather than HTTP), and every old link should land on the same page at the new address.

Quick workflow

  1. Open Delivery Rules for the account and go to the Redirects tab.
  2. In the Domain redirects card, press Add redirect.
  3. Under Redirect these domains, tick the domains to redirect; under For requests over, tick HTTP, HTTPS or both.
  4. Under To, choose Same protocol as the request, https:// or http://, and enter the target domain without a path, such as new.example.com. The Example line shows where /blog/post?id=7 goes.
  5. Press Save redirect, wait until the page shows Live, then check the redirect with curl.

Checks

  • The answer is a permanent redirect (301), and its Location keeps the path and query string: /blog/post?id=7 on the old domain goes to /blog/post?id=7 on the target.
  • On a domain whose certificate comes from Auto SSL, certificate checks under /.well-known/ keep working: over HTTP, those requests are answered by the domain's certificate-check rule, not by the redirect.
  • A redirect works where the edge serves the domain: over HTTP, a delivery rule lists the domain; over HTTPS, an HTTPS rule lists it and the domain has a certificate. When one is missing, the editor says the redirect has no effect there.
  • While the redirect is on, the domain's other rules stop applying over the redirected protocols, and the editor shows how many. Deleting the redirect serves the domain by its rules again.
  • While account-wide image optimization is on, .jpg, .jpeg and .png requests to a redirected domain are optimized and served instead of redirected; the redirect's row in the Domain redirects table and the editor say so for each domain.
  • Each domain has one redirect per protocol: the editor refuses a second redirect for a domain that another redirect already covers over the same protocol.
  • The editor refuses a redirect that would send a domain to itself over the same protocol. Redirecting http://www.example.com to https://www.example.com is not a loop, and the editor accepts it.

Frequently asked questions

How do I send HTTP visitors to HTTPS on the same domain?

Add a redirect for that domain, tick only HTTP under For requests over, choose https:// under To and enter the same domain. HTTP requests then get a 301 to the HTTPS address with the same path and query string, and HTTPS requests are served by the domain's rules as before. Make sure the domain already works over HTTPS with a certificate.

Do I redirect example.com and www.example.com separately?

Domains are matched as they are written, so tick every form you serve that should go to the target: when both example.com and www.example.com move to new.example.com, tick both. To settle on www.example.com, tick only example.com.

Why does the editor say the redirect has no effect?

The edge redirects a domain only where it serves it. Over HTTP, a delivery rule must list the domain; over HTTPS, an HTTPS rule must list it and the domain needs a certificate. Add the domain to a rule first, or finish its certificate.

What do the notes under a redirect in the table mean?

Each note says where the redirect does not work as written. Not used: an older redirect already covers that domain over that protocol; change or delete one of the two. A target with no protocol keeps browsers on the same domain: press Edit, check the protocol under To and press Save redirect. A domain with no rule, or no certificate, for a protocol is not redirected over it; add the domain to a rule or finish its certificate. While account-wide image optimization is on, .jpg, .jpeg and .png requests are optimized instead of redirected.

I deleted a redirect, but my browser still goes to the target.

Browsers remember permanent (301) redirects. Check with curl or a private window: after the delete, the domain is served by its rules again.

What about visitors on mobile browsers?

The Mobile redirect card on the same tab sends visitors on mobile browsers to another domain with a temporary (302) redirect, on every domain of this account, and keeps the path and query string. While it is on, mobile browsers get that 302 first. The mobile site domain must be one this account does not serve.