How to 301 Redirect Non-WWW to WWW URLs

Discussion in 'Apache' started by kesb, Nov 30, 2013.

  1. #1
    1.Find .htaccess file in root folder
    2.Open .htaccess file
    3.Delete all content
    4.Type in this code(using your domain ):
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} !^www.example.co.uk$ [NC]
    RewriteRule ^(.*)$ http://www.example.co.uk/$1 [L,R=301]
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
    
    </IfModule>
    Code (markup):
    5.Save the file
    6.Put file in root folder
    7.Upload file on the server( make sure you put .htaccess file in the root folder
    8.Check if the 301 redirect is successful use this page to check( personally myself using this one): http://www.stepforth.com/resources/server-header-checker-tool/#.Upp_YcRdX4b
    9.Make sure you see the following code within #1“HTTP Status Code: HTTP/1.1 301 Moved Permanently”
    10.That code will confirm the 301 redirect is being properly communicated.
    I've edited .htaccess file for my two websites
    http://www.eurodecorating.co.uk
    http://www.kjconversions.co.uk

    Works fine and you'll save your time!
    Any questions please ask.
     
    Last edited: Nov 30, 2013
    kesb, Nov 30, 2013 IP
  2. ultimate marketing

    ultimate marketing Greenhorn

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #2
    I find http://redirectdetective.com/ is a great tool for testing redirects.
     
    ultimate marketing, Dec 4, 2013 IP
  3. ABCname.com

    ABCname.com Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    Here is the most simplest rule to redirect non-www pages to www:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    Code (markup):
     
    ABCname.com, Dec 6, 2013 IP
  4. nvr24

    nvr24 Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    I have used kesb advice on my site http://www.njdeco.co.uk
    works fine for me.
    cheers
     
    nvr24, Dec 21, 2013 IP