How to Redirect Non-www to www URLs

How to Redirect Non-www to www URLs

Redirecting non-www requests to the www version of your website’s URL is beneficial for SEO purposes. Not only will it help you to avoid duplicate content on the Google index, but it will also avoid the possibility of split page rank and or split inbound links. In this article, we will learn how to redirect non-www to www URLs using the .htaccess file in your public_html folder.

Upgrade your Hosting and get up to 90% OFF Web Hosting Plans with Hostinger + Free SSL certificate!

Get Your Discount Here

Editing .htaccess File

To redirect a non-www URL to www, we need to place a rule in the .htaccess file. You can do it via FTP, SSH, or your control panel.

Follow the steps below to edit your .htaccess file from Hostinger’s hPanel:

  1. Head over to the Files section and open File Manager.
  2. Navigate to the public_html directory, right-click on the .htaccess file, and select Edit. If it doesn’t exist, refer to our tutorial to know how to create one.
    How to Redirect Non-www to www URLs
  3. Insert the following lines under the RewriteEngine On:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^ [NC]
    RewriteRule ^(.*)$$1 [L,R=301]
  4. Don’t forget to modify the code with your actual domain name instead of Once you’re done, don’t forget to save the changes.

Congratulations, you have successfully enabled a .htaccess rule that will redirect all visitors from a non-www URL to the www version of your website! Wasn’t hard at all, was it?


There you have it! 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

Hopefully, this tutorial was helpful. Let us know in the comments below if you face any issues.

The Author


Merkys M. / @merkys

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.


Rodrigo Athié Reply

February 12 2020



Dave Reply

August 02 2020

Thanks for the insight! Looking to do exactly this. I need to get my cdn working, and www is necessary for that. One question I have is in addition to www, I need it to go to https. Would I just add the https in place of the http?

Leave a reply




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

Become a part of Hostinger now!

More in Website