How to Redirect non-www to www URLs

In order to redirect all non-www requests to your site to the www version ( to, 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

Redirect non-www to www code:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

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!


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

About the author

Merkys M.

Merkys is a server administrator and Linux expert at Hostinger. He keeps everything up & running while tackling advanced server management issues. Besides that, he’s a big fan of blockchain technology, web development, and bodybuilding.

Add Comment

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get Exclusive Content

Join thousands of webmasters who get our free newsletter with tips on how to drive more traffic and revenue to their websites!

Please wait...

Thank you for sign up!

More in Website
Improving Website Performance – Serving Scaled Images