Cloudflare - how to redirect to the www. version of your website

It's common for a website to have DNS records for http://pcmltd.eu as well as http://www.pcmltd.eu. Most of the time, the version with www. is the one that is used. If you are not careful, you'll end up with both versions of the website being crawled by Google and other search engines. This could potentially lead to your Search Engine Optimisation (SEO) being diluted, as there are effectively two different websites with the same content.

If you are using Cloudflare for your site, there is a quick way to fix the issue. The following example assumes you wish to redirect http://pcmltd.eu to http://www.pcmltd.eu:

  1. Login to your account and find the site you wish to change
  2. Click onto Page Rules
  3. Click "Create Page Rule"
  4. Enter your site URL as follows in the first box:  siteurl.com/*
  5. Choose "Forwarding URL" from the dropdown and change "Select Status Code" to "301 - Permanent Redirect"
  6. In the "Destination URL" box, enter the following:   http://www.siteurl.com/$1
  7. Press "Save and Deploy"

Now, when a user tries to access a page such as http://siteurl.com/about-us, then will automatically 301 redirected to http://www.siteurl.com/about-us with a 301 redirect.

If you are using Drupal as your CMS of choice, there are rules in the .htaccess file allowing you to redirect all traffic to your preferred version of the URL. However, when you update the core of Drupal, these rules can be overwritten. By doing it this way, you avoid overwriting your .htaccess when updates are applied.

If you are not using Apache but not Cloudflare, the same can be achieved by putting some Redirect rules in your virtualhost config file.

Published: 29/09/2016

Do you have any questions?

Click on this message to find out how to contact us