Website

How to Redirect non-www to www URLs

Introduction

In order to redirect all non-www requests to your site to the www version (yourdomain.com to www.yourdomain.com), you should set the appropriate rewrite rule at the beginning of the .htaccess file in your public_html folder.
There are several benefits in doing that:

  • It will avoid duplicate content in Google.
  • It will avoid the possibility of split page rank and/or split link popularity (inbound links).

What you’ll need

Before you begin this guide you’ll need the following:

  • Access to Hosting control panel

Step 1 — Accessing File Manager

Login to your control panel and click on the File Manager in the Files section.

Hostingers File Manager location

Navigate to public_html directory and edit your .htaccess file. In case a file named .htaccess does not exist, you will need to create it by right clicking your mouse and selecting New File option.

Creating htaccess

If you hosting platform is on cPanel, the process of entering File Manager is the same. However, there are some additional steps that you will need to take in order to view hidden files as .htaccess

File Manager

You will get prompted with a pop-up menu asking what directory you would like to start in. To go directly to where your website files are stored make sure to check the Web Root and press Go button. Make sure that Show Hidden Files (dotfiles) option in File Manager is enabled.

File Manager options

You may check File Manager settings by clicking on Settings button inside your File Manager.

File Manager

Step 2 — Editing .htaccess file

Enter your .htaccess by right-clicking and selecting Edit option.

editing htaccess on hostinger file manager

If you are using cPanel, open your .htaccess file in Editor View.

File Manager

Insert the following lines to your .htaccess file. Don’t forget to modify the code with your actual domain name instead of yourdomain.com.

Redirect non-www to www code:

After you edit the code, don’t forget to Save your changes.

save non www url to www url redirection in htaccess

Congratulation, you have successfully enabled a .htaccess rule that will redirect all visitors from non-www to www version of your website!

Conclusion

By finishing this tutorial you have learned how to redirect non-www URLs to www. From now on, when someone accesses http://yourdomain.com they will be redirected to http://www.yourdomain.com. Instead of using the cPanel method, many people find changing the .htaccess file via FTP or SSH an easy alternative.

Add Comment

Click here to post a comment

Join thousands of subscribers worldwide

and get awesome deals & the newest tutorials to your email

Please wait...

Thank you for sign up!

More in Website
Improving Website Performance – Serving Scaled Images

Close