How to redirect my site to use the WWW (using the .htaccess file)


Many reasons can justify the usage of the « www » subdomain for your website. Whether to install an SSL Certificate, the installation of a CDN (Content Delivery Network) like CloudFlare or simply for the look of your URL address. Today we’ll suggest and show you a method for doing so without causing any damage to your search optimization effort (SEO).

For Websites NOT Using WordPress

To create the redirection, you will need to modify a file inside your web hosting. The file we will need to modify is called the “.htaccess” file. This file, if created, is usually hidden.

Warning, if your website is powered with WordPress, do not use this method, I’ve added a section at the bottom of the blog specifically for sites using WordPress

In order to modify this file, we’ll be using tools that are available inside the cPanel. In your control panel, you first need to open the “File Manager”.

cPanel File Manager

Once you’re in the file manager, you’ll need to make sure all the hidden files are being shown. Select the option “Setting” in the upper right corner (1) and make sure that there’s a check in the “Show Hidden Files” (2).

cPanel File Manager hidden files

Next step is to locate the « .htaccess » file so we can modify it. In general the file will be in the “public_html” folder. Click on the “public_html” folder in the left section and you should be able to see the file we are looking for in the right section.

cPanel File Manager directory

For all those that can’t see the file, you’ll need to create it. Select he option “+ File” in the upper right, write down the name of the file “.htaccess” and save.

cPanel File Manager new file

We finally arrive at the file modification. Right click on the file and choose the “Edit” option.

You will need to add the following lines at the end of the file:

RRewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Replace with your actual domain name

Let’s take a closer look at the code we’ve just added in the file. The first line “RewriteEngine On” is telling the server that we’ll change the default behaviour of the URL. The second line is the condition that must be meet before rewriting the URL “RewriteCond %{HTTP_HOST} !^$ [NC]”. In this example, the server will rewrite the URL only if there is no “www” in front. The last line is the actual rewriting rule “RewriteRule ^(.*)$$1 [L,R=301]” telling the system to add the “www” to the URL. The most important part in this line is the “[R=301, L]” which will indicate to Google and all the other search engines that the change is permanent. By doing so this will not affect your search optimization effort.

For Websites Using WordPress

For WordPress users, adding the “www” in front of your domain is a lot easier. The changes must be made from within your WordPress administration control panel.

In your WordPress control panel you must select the general setting. You will need to add the “www” in front of both URL shown in the general settings tab.

WordPress Admin Panel

Once the changes are applied and saved, your site will now be using the « www ».

Should you have any question or comments concerning this tutorial, feel free to contact us. We are always happy to answer all requests.