How to set up global redirects of domain to different domain and sub-domain

We are transitioning our Shopify ecommerce website (on a Cloudflare managed domain) i.e. domain.com to what will be a sub-domain of a completely different domain i.e. shop.example.com (on a Cloudflare managed domain as well). All content/URLs/paths will remain the same from old domain to new domain and new subdomain. I have read the CF documentation and want to create a global redirect rule, however since the stakes are very high, I want to validate to ensure that we do not make a mistake. It also seems that this could be done several ways (Redirect Rules, Origin Rules, Page Rules, etc.)

Some example paths are below:

From: domain.com
To: shop.example.com

From: domain.com/products/product-url-is-here
To: shop.example.com/products/product-url-is-here

From: domain.com/collections/collection-name
To: shop.example.com/collections/collection-name

Would appreciate any input you have. Also open to other suggestions.

Create a redirect rule here…
https://dash.cloudflare.com/?to=/:account/:zone/rules/redirect-rules

Copy this example exactly…

Then you need to create a DNS record for the domain you are redirecting from in your Cloudflare dashboard…
https://dash.cloudflare.com/?to=/:account/:zone/dns/records

Add a proxied dummy value of A 192.0.2.1 or AAAA 100:: as the domain is being redirected and there’s no real origin server.

1 Like

Thank you SJR for taking the time to respond! This very helpful and all makes sense.

  1. Do you know an effective way to test this in advance?

  2. Do you know of a way to schedule this to be enabled?

You can create the rule for a subdomain instead for test. Once working then use the switch on the redirect page to turn it off, change the hostname to the actual domain, then switch the redirect back on when you are ready.

If the switch needs to be automated, you’ll have to use the Cloudflare API to control things.

1 Like

Thank you!!!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.