Using CloudFlare for redirection

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:

The additional domains are like this:

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:

How this is done is simple. Firstly we configure each additional domain in CloudFlare DNS:

TYPENAMECONTENTPROXY STATUS
CNAME*customer.orgProxied
CNAMEcustomer.netcustomer.orgProxied

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.

TYPENAMECONTENTPROXY STATUS
CNAME*subdomain1.customer.orgProxied
CNAMEsubdomain1.worldsubdomain1.customer.orgProxied

Then we create a Page Rule:

URL: *subdomain1.world/*
Setting: Forward URL (301 Permanent Redirect)
Destination URL: https://subdomain1.customer.org/$2