URL Forwarding or Redirects using Cloudflare Rules

Link: https://support.brilliantdirectories.com/support/solutions/articles/12000090120-url-forwarding-or-redirects-using-cloudflare-rules

Domain forwarding is a technique for making all of the URLs of a primary domain available from additional domains by redirecting all of the requests made to the additional domains to the same URL on the primary domain.

Unlike other techniques such as domain masking, which causes the content of a primary domain appear to also be present on additional domains, domain forwarding redirects all traffic to the primary domain, avoiding duplicate content penalties that can negatively impact the SEO of the primary domain.

For example, implementing domain forwarding from olddmain.com to newdomain.com will cause the following URLs:

https://www.olddomain.com
https://www.olddomain.com/members
https://www.olddomain.com/join


To redirect to:


https://www.newdomain.com
https://www.newdomain.com/members
https://www.newdomain.com/join



One easy and free way to accomplish this is using Cloudflare's Page Rules tool. For the remaining of this guide, we will refer to the URL that is being redirected as the Old Domain and the destination URL as the New Domain.

1. First, connect the old domain to Cloudflare by following the steps in this guide


2. Navigate to the Cloudflare account for the domain the URL forwarding is going to be set up.

    



3. Make sure the old root domain has a valid A Record and create a CNAME record that points the www subdomain to olddomain.com. Also, make sure that these records are listed as "Proxied" in the "Proxy status" column:


 


4. Navigate to Rules > Page Rules:




5. Under Page Rules, click "Create Page Rule":




6. Enter the old domain, followed by /*. By using the asterisk (/*) character, the rule will impact all URLs of the domain, such as /members, / join, and all others:




7. Select "Forwarding URL" from the "Pick a Setting" drop-down menu, and choose between "301 - Permanent Redirect" or "302 - Temporary Redirect".  The vast majority of users will want to select the "#10 - Permanent Redirect" option:




8. Enter the destination URL, followed by /$1.

The /$1 is necessary for the new domain to receive the URL that was entered for the old domain. For example, if a user requested olddomain.com/members, they would be redirected to newdomain.com/members.  If the /$1 was not present, olddomain.com/members would simply be redirected to newdomain.com:




In order to successfully cover both the www version and the non-www version of your Old Domain, please create two separate rules - the WWW version and the non-WWW version.

WWW Version:




NON-WWW Version: