How to redirect non-www urls to www?
Redirecting non-www requests to the www version of your website URL is good for SEO. Not only will this help you avoid duplicating content on Google, but it will also avoid splitting your inbound links on 2 different URLs. In this article, we will learn how to redirect non-www URLs to www URLs using the .htaccess file in your public_html folder.
To redirect a non-www url to www, we need to add a rule in the .htaccess file. You can do this via FTP, SSH, or more simply via your cPanel control panel.
Follow the steps below to edit your .htaccess file from cPanel Ex2:
Before you start, you need to log in to your cPanel account.
Go to the Files section and open File Manager.
Navigate to the public_html directory
Right-click on the .htaccess file and select Edit. The file may not be visible, if so, click "**Settings**" at the top right of your File Manager, then select "**Show hidden files**" then click "**Save**".
If a screen appears asking you to confirm the encoding, choose utf-8 (if you are using a Western language) and click EDIT.
Insert the following lines (Note : If RewriteEngine On is already registered on the file, do not rewrite) :
Warning ! Remember to change the code with your current domain name instead of yourdomainname.com. Once you're done, don't forget to save the changes.
Congratulations, you have successfully activated a .htaccess rule that will redirect all visitors from a non-www url to the www version of your website! It wasn't difficult at all, was it?
There you go ! By completing this tutorial, you have learned how to redirect non-www urls to www. Now when a person accesses http://yourdomain.com, they will be redirected to http://www.yourdomain.com.
Here's how to redirect non-www urls to www
Editing the .htaccess file
To redirect a non-www url to www, we need to add a rule in the .htaccess file. You can do this via FTP, SSH, or more simply via your cPanel control panel.
Follow the steps below to edit your .htaccess file from cPanel Ex2:
Before you start, you need to log in to your cPanel account.
Go to the Files section and open File Manager.
Navigate to the public_html directory
Right-click on the .htaccess file and select Edit. The file may not be visible, if so, click "**Settings**" at the top right of your File Manager, then select "**Show hidden files**" then click "**Save**".
If a screen appears asking you to confirm the encoding, choose utf-8 (if you are using a Western language) and click EDIT.
Insert the following lines (Note : If RewriteEngine On is already registered on the file, do not rewrite) :
RewriteEngine On RewriteCond %{HTTP_HOST} ^votrenomdedomaine.com [NC] RewriteRule ^(.*)$ http://www.votrenomdedomaine.com/$1 [L,R=301]
Warning ! Remember to change the code with your current domain name instead of yourdomainname.com. Once you're done, don't forget to save the changes.
Congratulations, you have successfully activated a .htaccess rule that will redirect all visitors from a non-www url to the www version of your website! It wasn't difficult at all, was it?
There you go ! By completing this tutorial, you have learned how to redirect non-www urls to www. Now when a person accesses http://yourdomain.com, they will be redirected to http://www.yourdomain.com.
Updated on: 14/02/2023
Thank you!