How to setup URL redirect to keep sub-domain and path on Cloudflare?


#1

Hello. Any suggestion on how to achieve the below setting? By DNS setting?

When visitor go to:
subdomain.domainA.com/path-example

They will be redirected to:
subdomain.domainB.com/path-example

So, basically the goal is to keep whatever sub-domain and whatever path while redirecting.

Thanks!


#2

The DNS for subdomain.domaina.com will need to be in the DNS tab at Cloudflare (pointing to anything) and :orange:. You’ll need to add a record for each subdomain you want to redirect, as wildcard records can’t be :orange:.

Then you can create a Page rule for domaina at so:

Matching url *.domaina.com/*
Settings:
Forwarding URL - 301 redirect
Enter the value as https://$1.domainb.com/$2.

image

You can see this rule in action:

https://sub.cloudflaretools.com/path/b


#3

Thanks a lot.

It works !