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

Need help with my .htaccess file

Discussion in 'White Hat SEO' started by Aty, Feb 19, 2015.

  1. Aty

    Aty Jr. VIP Jr. VIP

    Joined:
    Jan 27, 2011
    Messages:
    5,957
    Likes Received:
    4,068
    Home Page:
    ---- THREAD CLOSED 02/19/2015 ----
    So my .htaccess file currently looks like this and it is working fine.

    Code:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase / 
    RewriteCond %{HTTP_HOST} ^example.com [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
    
    Now I would like to redirect two 404 pages to the homepage for the link juice.

    I tried like this below but for some reason I cannot access the homepage anymore.

    Code:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase / 
    RewriteCond %{HTTP_HOST} ^example.com [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
    
    Redirect 301 /index.htm http://www.example.com/
    Redirect 301 /m http://www.example.com/
    
    Anyone has a working code for my above described needs?
     
  2. kbklash

    kbklash Senior Member

    Joined:
    Jun 2, 2012
    Messages:
    1,140
    Likes Received:
    449
    Location:
    in my BMW to my BHW
    Home Page:
    I guess addding

    Code:
    ErrorDocument 404 http://'yourhomepage'.com
    will do the job.This will redirect the missing pages to your homepage.
     
    • Thanks Thanks x 1
  3. hpasha

    hpasha Jr. VIP Jr. VIP

    Joined:
    May 15, 2011
    Messages:
    1,339
    Likes Received:
    185
    Location:
    Kepler 186F
    • Thanks Thanks x 2
  4. Gogol

    Gogol Jr. VIP Jr. VIP

    Joined:
    Sep 10, 2010
    Messages:
    3,409
    Likes Received:
    3,057
    Gender:
    Male
    Replace your .htaccess with this:

    Code:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase / 
    Redirect 301 /index.htm http://www.example.com/
    Redirect 301 /m http://www.example.com/
    RewriteCond %{HTTP_HOST} ^example.com [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
    
    Your current code does not work because you have defined a redirect rule as [L], or Last rule. So further rules will not be processed if that rule is processed.. hope that helps :)
     
    • Thanks Thanks x 1
    Last edited: Feb 19, 2015
  5. Aty

    Aty Jr. VIP Jr. VIP

    Joined:
    Jan 27, 2011
    Messages:
    5,957
    Likes Received:
    4,068
    Home Page:
    Still not working.

    It's not a Wordpress website and I would like to redirect only two pages.
     
  6. Gogol

    Gogol Jr. VIP Jr. VIP

    Joined:
    Sep 10, 2010
    Messages:
    3,409
    Likes Received:
    3,057
    Gender:
    Male
    I got your message with the screenshot. Sorry it was a mistake on my end that created the "inifinite redirect error" :p

    Try the following instead:

    Code:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^index.htm$ / [L,R=301]
    RewriteRule ^m$ /  [L,R=301]
    RewriteCond %{HTTP_HOST} ^example.com [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
    
    Let me know if this works. :)

     
    • Thanks Thanks x 1
    Last edited: Feb 19, 2015
  7. kbklash

    kbklash Senior Member

    Joined:
    Jun 2, 2012
    Messages:
    1,140
    Likes Received:
    449
    Location:
    in my BMW to my BHW
    Home Page:
    You may use the below method to redirect custom urls

    To redirect index.htm to youhomepage.php

    Code:
    RedirectMatch 301 ^/index\.htm$ /'yourhomepage.php
    Here it's using the regular expression,and is comparing against the URL given.In this case 'index.htm'.

    You can use this for any number of pages.
     
    • Thanks Thanks x 1
    Last edited: Feb 19, 2015
  8. Aty

    Aty Jr. VIP Jr. VIP

    Joined:
    Jan 27, 2011
    Messages:
    5,957
    Likes Received:
    4,068
    Home Page:
    This one works fine, thank you. :)