1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Redirection (301) - Htaccess Tutorial

Discussion in 'White Hat SEO' started by extremephp, Dec 4, 2010.

  1. extremephp

    extremephp BANNED BANNED

    Joined:
    Oct 19, 2010
    Messages:
    1,293
    Likes Received:
    1,272
    I thought, this would help some people, atleast some who doesnt Google much!


    How to Save an Htaccess file
    1.Open Notepad
    2.Type in the Htaccess commands
    3. File > Save
    4.remove .txt and type .htaccess
    5. From File type, select All Files.
    6. Save
    7. Done!


    Q: I see my site having 100 backlinks with WWW and 10 Without WWW
    A : 301 Redirect WWW to Non WWW or Vice Versa!


    WWW to Non WWW


    #Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{http_host} ^sitenamehere.com
    RewriteRule ^(.*) http://www.sitenamehere.com/$1 [R=301,L]


    Non WWW to WWW

    #Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{http_host} ^http://www.sitenamehere.com
    RewriteRule ^(.*) http://sitenamehere.com/$1 [R=301,L]


    Q: I bought an SSL! And I want to force my url to be https://
    A: Can be done with out without WWW. (codes below)

    Non WWW to WWW with Https

    #Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{http_host} ^sitenamehere.com
    RewriteRule ^(.*) https://www.sitenamehere.com/$1 [R=301,L]

    WWW to Non WWW with Https

    #Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{http_host} ^http://www.sitenamehere.com
    RewriteRule ^(.*) https://sitenamehere.com/$1 [R=301,L]


    Q : I dont want my site to come with .html, .php extensions
    A: Can easily be hidden!



    Hiding Page Extentions


    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php

    Replace .php with .html .txt or whatever you need to hide!


    Q: Google deindexed my site. I need all the link juice to my new site. And I dont want to break the old urls.

    A: 301 olddomain.com/page to newdomain.com/page
    . Kick Googles Butt using this htaccess mod!


    Domain.com/page to newdomain.com/page

    #Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www.yourolddomain.com$[OR]
    RewriteCond %{HTTP_HOST} ^yourolddomain.com$
    RewriteRule ^(.*)$ http://www.yournewdomain.com/$1 [R=301,L]


    Am not a pro in htaccess, but if you have some problems with this, Ask loud!


    ~ExP~
     
    • Thanks Thanks x 10
  2. emil4008

    emil4008 Junior Member

    Joined:
    Dec 3, 2009
    Messages:
    142
    Likes Received:
    2
    I am trying to make a redirect to entire site but it doesn't work. I am using this code - redirect 301 / http://www.mynewdomain.com/.
    The host doesn't support PHP/CGI/ASP/FPext scripts.
    Could this be the reason?
     
  3. vcjohnny

    vcjohnny Regular Member

    Joined:
    Dec 2, 2010
    Messages:
    284
    Likes Received:
    38
    thanks for the tut
     
  4. andreyg13

    andreyg13 Jr. VIP Jr. VIP

    Joined:
    Nov 13, 2009
    Messages:
    915
    Likes Received:
    1,774
    Occupation:
    SEO
    Location:
    http://seoshark.org
    Home Page:
    good share buddy, was actually looking for this today
     
  5. extremephp

    extremephp BANNED BANNED

    Joined:
    Oct 19, 2010
    Messages:
    1,293
    Likes Received:
    1,272
    All hosts does follow htaccess rules. Just follow what the code above, and you will be able to get it working!


    :)

    ~ExP~
     
  6. roman_tyk

    roman_tyk Newbie

    Joined:
    Dec 24, 2010
    Messages:
    41
    Likes Received:
    1
    Location:
    Wroclove
    Good tutorial, very usefull.
     
  7. yusuf0024

    yusuf0024 Regular Member

    Joined:
    Sep 13, 2009
    Messages:
    289
    Likes Received:
    63
    Last edited: Dec 27, 2010
  8. esl753

    esl753 Newbie

    Joined:
    Sep 28, 2009
    Messages:
    46
    Likes Received:
    3
    Occupation:
    Web design
    Location:
    CA
    i recently changed the .htaccess file on a Joomla shopping cart site and now my site is being indexed with the "https" how do i get rid of this??? please help ... Thanks in advance
     
  9. gettinthere

    gettinthere Regular Member

    Joined:
    Apr 17, 2010
    Messages:
    356
    Likes Received:
    57
    I did mine though my cpanel (change of domain) & this is the .htaccess it produced:

    Code:
    RewriteEngine On
    RewriteRule ^.*$ http://www.mynewsite.com [R=301]
    Is this acceptable for changing domain & retaining link juice?

    What is the difference between [r=301] & [r=301,L] ? I also seen a few other "extensions"

    Thanks
     
    Last edited: Mar 30, 2011
  10. mrfuong

    mrfuong Newbie

    Joined:
    May 25, 2010
    Messages:
    14
    Likes Received:
    1
    thanks for sharing
     
  11. SupaMonkey

    SupaMonkey Regular Member

    Joined:
    Apr 2, 2010
    Messages:
    422
    Likes Received:
    74
    Location:
    South Africa
    Home Page:
  12. SupaMonkey

    SupaMonkey Regular Member

    Joined:
    Apr 2, 2010
    Messages:
    422
    Likes Received:
    74
    Location:
    South Africa
    Home Page:
    Oh, and I failed to mention, I only want the rule to affect the subdirectory - not any further subdirectories of file names.
     
  13. Autumn

    Autumn Elite Member

    Joined:
    Nov 18, 2010
    Messages:
    2,197
    Likes Received:
    3,041
    Occupation:
    I figure out ways to make money online and then au
    Location:
    Spamville
    "L" stands for "last rule" - it orders apache to stop rewriting after the line ending with "L" has been processed.
     
  14. dotcum

    dotcum Regular Member

    Joined:
    Jan 12, 2010
    Messages:
    277
    Likes Received:
    41
    Occupation:
    Internet Marketer/Cab Driver
    Location:
    S Ozone Park NY
    Hey, I have been trying to do some 301 redirects because I noticed that I have 98 "404 Not Found " for my main site in G webmasters tool. So I tried the code below on 1 of my html sites and it worked fine but when I tried it on my wordpress(main site) all my post are getting "Not Found" error. I know that there are wp plugins to do this that works perfect, but I dont want to use a plugin because I prefer to do manually. Can you please tell me what the correct 301 redirect code for wordpress is?

    301 CODE I tried in .htaccess

    Redirect 301 /page http://www.mysite.com/newpage/

    This is the genertated .htaccess that I found in my ftp currently:

    RewriteEngine on

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress
     
  15. dotcum

    dotcum Regular Member

    Joined:
    Jan 12, 2010
    Messages:
    277
    Likes Received:
    41
    Occupation:
    Internet Marketer/Cab Driver
    Location:
    S Ozone Park NY
    Anyone with experience please any suggestions to my post above.