Home / Frontend Codes and Demos / .htaccess / How to redirect non-www URL’s to www using .htaccess?
How to redirect non-www URL's to www using .htaccess?

From this article you can learn and how to redirect non-www to www using .htaccess. Ensure that you specify the new host as canonical in all page links or sitemaps. Use 301 redirects to route traffic from the previous host to the new host.

How to redirect non-www URL’s to www using .htaccess?

How to redirect non-www URL's to www using .htaccess?

From this article you can learn and how to redirect non-www to www using .htaccess. Ensure that you specify the new host as canonical in all page links or sitemaps. Use 301 redirects to route traffic from the previous host to the new host.

This tutorial will explain you how to add www to your domain.If you hold a website and want the web site to be run in www infront of the domain, not with non-www domain, then please follow the steps below

Steps to follow how to add www from non-www domain

Step 1:

Open .htaccess file from your root folder of the project else create one for your website and place that in root folder.

Video demo for how to create .htaccess?

Step 2:

Add below code to .htaccess file. Below code will help you to achieve to add www to the website domain

 RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] // [R=301,L] will help to redirect from old to new domain 

Note: Change “example” to your domain name.

Demo

If you click w3tweaks.com it will redirect to www.w3tweaks.com

About CV

I'm frontend developer