301 Redirect on A Ecommerce with .htaccess

Discussion in 'Search Engine Optimization' started by androide, Jun 9, 2011.

  1. #1
    Hello,
    I have a doubt about creating a 301 redirect on a ecommerce website with apache and .htaccess.

    The ecommerce structure is this:
    home
    home/cat1
    home/cat1/cat2
    home/cat1/cat2/cat3
    home/cat1/cat2/cat3/product1
    home/cat1/cat2/cat3/product2
    ....


    I simply want to redirect all "product pages" to theirs category pages.


    If I could make it manually I would insert in the .htaccess file:
    redirect 301 /cat1/cat2/cat3/product1 www.home.com/cat1/cat2/cat3

    But I can't do that for 15000 pages for every category. Is there anything that could automatically redirect the "product pages" to their category?

    Let me know,
    Thank you
     
    Last edited: Jun 10, 2011
    androide, Jun 9, 2011 IP
  2. petrustone

    petrustone Peon

    Messages:
    18
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    petrustone, Jun 9, 2011 IP
  3. Intermg

    Intermg Active Member

    Messages:
    1,282
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    65
    #3
    Try using mod_rewrite instead of Redirect directive.
     
    Intermg, Jun 9, 2011 IP
  4. androide

    androide Peon

    Messages:
    217
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hello,
    I made a mistake. I didn't want to write this:
    but this one:
    Sorry for the treuble. I just correct my original post.

    Thank you for your answer.
     
    androide, Jun 10, 2011 IP
  5. petrustone

    petrustone Peon

    Messages:
    18
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    A quick and dirty solution depending on the category structure is to write a redirect fo each cat. Note that your products match the (.*)

    Try this code:

    RewriteEngine on
    RewriteBase /
    RewriteRule ^cat1/cat2/cat3/(.*) http://www.home.com/cat1/cat2/cat3/ [R=301,L]
    
    Code (markup):
    I am not an expert, so try it before deploy it. :eek:
    If the cat structure is more complicated you might need a more complex model.
    Let us know if it worked for you.
     
    petrustone, Jun 10, 2011 IP
  6. androide

    androide Peon

    Messages:
    217
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    it works! Thank you.
     
    androide, Jun 11, 2011 IP