Using CloudFlare for redirection
How to use CloudFlare DNS and Page Rules to redirect one domain to another.
One of our customers bought 7 domains to secure their brand name. The main domain was customer.org but they also bought 6 additional domains and needed to redirect to the main website. The main domain is like this:
customer.org: main website
subdomain1.customer.org: another website
subdomain2.customer.org: another website
The additional domains are like this:
subdomain1.world
The rule was that:
Redirect all HTTP to HTTPS.
Redirect all domains to the main domain while retaining the full path.
Redirect subdomains correspondingly.
Thus, some redirect examples will be:
customer.net/path/sub/page1 becomes customer.org/path/sub/page1
submain1.customer.net/path/sub/page2 becomes subdomain1.customer.org/path/sub/page2
subdomain1.world/path/sub/page2 becomes subdomain1.customer.org/path/sub/page2
How this is done is simple. Firstly we configure each additional domain in CloudFlare DNS:
TYPE | NAME | CONTENT | PROXY STATUS |
CNAME | * | customer.org | Proxied |
CNAME | customer.net | customer.org | Proxied |
Then we create a Page Rule:
URL: *customer.net/*
Setting: Forward URL (301 Permanent Redirect)
Destination URL: https://$1customer.org/$2
We also do the same for the subdomain-related domains.
TYPE | NAME | CONTENT | PROXY STATUS |
CNAME | * | subdomain1.customer.org | Proxied |
CNAME | subdomain1.world | subdomain1.customer.org | Proxied |
Then we create a Page Rule:
URL: *subdomain1.world/*
Setting: Forward URL (301 Permanent Redirect)
Destination URL: https://subdomain1.customer.org/$2