How to create a 301 redirect to redirect a non www URL to a www URL using the .htaccess file

16 sec read

  1. Create a .htaccess file within your web directory where all your website files are located
  2. Add the following code to it
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^$
    RewriteRule ^/?(.*)$ "http\:\/\/www\.yourdomain\.com\/$1" [R=301,L]

    Replace with your website address

  3. This will ensure that when is entered in the address bar it will redirect to, this will help so that search engines won’t pick up duplicate content for your website

Last Updated On March 22, 2018

Leave a Reply

Notify of