correct 301 redirect methord???

Discussion in 'robots.txt' started by shaun_ru_th, May 31, 2011.

  1. #1
    can anyone pls tell me the correct version of the 301 redirect code from following 3, 301 redirect codes???

    example 1 (currently using)
    -------------------------------------------------
    RewriteEngine ON
    RewriteCond %{HTTP_HOST} !^(.*).example.com$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

    example 2
    -------------------------------------------------
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^http://example.com[NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]


    example 3
    -------------------------------------------------
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]



    I prefer www version instead of non www version and I m currently using example 1 code..


    is there any difference between these 3 codes???
     
    Last edited: May 31, 2011
    shaun_ru_th, May 31, 2011 IP
  2. manish.chauhan

    manish.chauhan Well-Known Member

    Messages:
    1,682
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    110
    #2
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

    is the correct way to redirect non-www version to www version.
     
    manish.chauhan, Jun 3, 2011 IP
  3. Merkucio

    Merkucio Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I'm using this way:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>

    Options +Indexes
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    RewriteCond %{HTTP_HOST} ^www\.xxxxxxxxxxx\.xxx [NC]
    RewriteRule ^(.*)$ http://xxxxxxxxxxx.xxx/$1 [R=permanent,L]
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(.*)/$
    RewriteRule ^(.*)$ http://www.xxxxxxxxx.xxx/$1/ [L,R=301]
    </IfModule>

    # END WordPress
     
    Merkucio, Jun 4, 2011 IP
  4. apotohosting

    apotohosting Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi guys

    I have seen at many place to redirect url
    code is

    redirect301"/domin.html" http://www.domin.com

    Please tell me where it will be use and what about

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

    please guied me
     
    apotohosting, Jun 10, 2011 IP
  5. shehpati

    shehpati Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    When there is an option of choosing between www n non www domain name in wordpress admin panel, why would be there any need of this redirect? n do we need to add this redirect in htaccess always? or there are special circumstances? e.g first we see our search results n if there are duplicate contents in search results then add this redirect in our htaccess?
     
    shehpati, Jun 14, 2011 IP
  6. upendraets

    upendraets Peon

    Messages:
    106
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]


    is a best way
     
    upendraets, Jun 25, 2011 IP