What's Wrong with my .htaccess code?

Discussion in 'Site & Server Administration' started by finqoo, Oct 9, 2010.

  1. #1
    I am trying to get my links to redirect to something a little more search engine friendly but for some reason I am getting a 404 error. What's wrong with this code?

    
    Redirect 301 /default.htm http://www.site.com/index.htm
    Redirect 301 /links.htm http://www.site.com/links/links.htm
    ErrorDocument 404 http://www.site.com/404.htm
    RewriteEngine on
    RewriteRule ^products_2\.htm$ /2/keyword.htm
    RewriteRule ^products_3\.htm$ /3/keyword.htm
    RewriteRule ^products_4\.htm$ /4/keyword.htm
    RewriteRule ^products_5\.htm$ /5/keyword.htm
    RewriteRule ^products_6\.htm$ /6/keyword.htm
    
    Code (markup):
    Thanks for your help :)
     
    finqoo, Oct 9, 2010 IP
  2. zacharooni

    zacharooni Well-Known Member

    Messages:
    346
    Likes Received:
    20
    Best Answers:
    4
    Trophy Points:
    120
    #2
    Why use mod_rewrite, just use

    Redirect 301 /products_2.htm /2/keyword.htm
     
    zacharooni, Oct 10, 2010 IP
  3. finqoo

    finqoo Well-Known Member

    Messages:
    319
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    105
    #3
    Because /2/keyword.htm doesn't exist, it's a fake directory and a generated keyword.
     
    finqoo, Oct 11, 2010 IP
  4. MrYu

    MrYu Peon

    Messages:
    157
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That's why you are getting 404s -- /2/keyword.htm doesn't exist. It should be the other way around, first what to rewrite, then what to rewrite it into.

    So, RewriteRule /2/keyword.htm$ /products_2\.htm

    So, if you type /2/keyword.htm in your browser, the server is going to show products_2.htm
     
    Last edited: Oct 12, 2010
    MrYu, Oct 12, 2010 IP