How to Redirect Non-www to www URLs
access_time
hourglass_empty
person_outline

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.

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} ^yourdomain.com [NC]
    RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
  4. Don’t forget to modify the code with your actual domain name instead of yourdomain.com. 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?

Conclusion

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 http://yourdomain.com, they will be redirected to http://www.yourdomain.com.

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

The Author

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.

Related tutorials

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

Become a part of Hostinger now!

More in Website
Improving Website Performance – Serving Scaled Images

Close