How to do a redirect from one domain to another straight from CloudFlare

Often it is needed to place a redirect from all pages in one domain to all pages (or a home page) in other domain and while the standard .htaccess file method on the server still works, for CloudFlare users there is a more efficient way to do that.

To redirect all pages from one domain to another one, do the following:

  1. Log into the CloudFlare and add the domain from which you want to redirect from. Choose the “Free” plan and skip the scanning of DNS records
  2. Go to the newly created domain profile and choose “DNS” -> “Records” section
  3. Add an A record for with a name of @ (at symbol) and point it to the IPv4 address: 192.0.2.1
  4. Add a CNAME record with a name of www and set the @ (at symbol) as a target
  5. Now switch to the “Rules” -> “Redirect Rules” section at the domain profile and press on “Create rule” button
  6. Set “Redirect all to mytargetdomain.tld” as the rule name, choose the conditional as “All Incoming Requests

If you want to redirect all requests to the home page of the target domain:

7. Choose the “Type” in the statement as “Static” and set the “URL” as “https://mytargetdomain.tld” (the home url of your target domain)

8. Leave the “Status code” as 301 if you want to do a permanent redirect or change it to 302 if you want to do a temporary redirect

If you want to redirect all pages from one domain to all pages in another domain:

7. Choose the “Type” in the statement as “Dynamic” and add the following command in the “Expression” field (where https://mytargetdomain.tld is the root/home URL of your domain):

8. Leave the “Status code” as 301 if you want to do a permanent redirect or change it to 302 if you want to do a temporary redirect

9. If you want to redirect also the query strings (e.g. ?myvar=1&myvar=2) tick the checkbox “Preserve query string

10. Save the newly created redirect rule

Leave a Comment on How to do a redirect from one domain to another straight from CloudFlare
About the author
I'm a full-stack WordPress developer with a 10+ years of solid experience in the core web development languages, development processes / techniques, web security, Linux server management and with pretty good understanding about proper semantics, UX/UI, technical SEO, good design and basic knowledge of company leadership. On top of that - a distant 5+ years experience as a computer and electronics repair technician which often enables me to understand also how the things work at the hardware level.
Your feedback matters!…
I hope you found this article helpful. Feel free to add some comments - your feedback is very important to me, as it drives my motivation and helps me to improve the content.