1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Mod_rewrite format change, need 301 help!

Discussion in 'Apache' started by theblade24, Sep 27, 2005.

  1. #1
    I am currently using this url format for about 500 links on my site

    www.xxxxxxxxxxxx.com/cp-app/prod/body-jewelry/MM-12345.html

    cp-app is cp-app.cgi?
    prod is short for product page
    body-jewelry is just a fake directory for the keywords to be in the url
    MM-12345 is my product id

    I'm achieving this with this rewrite rule:

    RewriteRule ^cp-app/([^/]*)/body-jewelry/([^/]*)/?\.html$ shop/cgi-bin/cp-app.cgi?pg=$1&body-jewelry&ref=$2 [L]

    I'd like to change this and add the product name to the end of the url using this which works fine:

    RewriteRule ^cp-app/([^/]*)/body-jewelry/([^/]*)/([^/]*)/?\.html$ shop/cgi-bin/cp-app.cgi?pg=$1&body-jewelry&ref=$2&product_name_encoded=$3 [L]

    I now need to somehow globally redirect all those links done the first way to the second way with a 301 redirect.

    It has been suggested to use this:

    RewriteRule ^cp-app/prod/body-jewelry/(.*)?\.html$ http://www.xxxxxxxxxxxx.com/cp-app/prod/body-jewelry/$1/$2?\.html [R=301,L]

    which unfortunately isn't working.

    Can someone give me some advice on how to correct this redirect so all my links in Google the old way will hit and be redirected to the new way?

    Thanks!
     
    theblade24, Sep 27, 2005 IP
  2. johnt

    johnt Peon

    Messages:
    178
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The problem is that the old-style URLs do not include any easy indication of what the product name is. You will presumably have to do a database lookup using the product id to determine what product name should be put into the new-style url.
    I think that the RewriteMap directive will allow you to do something like this, but I've never used it so can't really help you, I'm afraid.

    Hope the link helps

    John
     
    johnt, Sep 28, 2005 IP
  3. theblade24

    theblade24 Active Member

    Messages:
    84
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #3
    Well really, the old style url doesn't have ANY indication as to the product name, only the product id.

    I guess the first attempt was to tell it to match up to a certain point and what ever is after product id didn't matter because the unique product id was the end of the match point.

    I can't work like that with some kind of wildcard after the product id?

    I'm obviously trying to globally redirect alot of links.

     
    theblade24, Sep 28, 2005 IP
  4. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,888
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #4
    The new URL just wants to add more stuff. So there's no way to tell the server what is what.

    www.mydomain.com/cp-app/prod/sports-memorabilia/MM-12345
    www.mydomain.com/cp-app/prod/sports-memorabilia/MM-12345/pokemon-is-funny.html

    Apache would proably think

    MM-12345/pokemon-is-funny.html is the same thing as
    MM-12345

    If the URL had gone from

    www.mydomain.com/cp-app/prod/sports-memorabilia/ANTHING/code
    to
    www.mydomain.com/cp-app/prod/sports-memorabilia/ANYTHING/ANYTHING

    then it would of probably bene possible.

    Post a script URL (non-mod-rewrite URL) and I can post the code to make both URLs work and then as Google crawls the site, it'll see the new URLs.
     
    Nintendo, Sep 28, 2005 IP
  5. theblade24

    theblade24 Active Member

    Messages:
    84
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #5
    First let me say, this is a test situation on a non-live site. The first method is live on a site with product links being used everyday in format #1. The world or search engines have not seen the new method yet, so that rule can be changed to make it work and be redirected to from the first method if something needs to change.

    _________________________________________________________________

    Here is the original link system:

    w.xxxxxxxxxxxxxxx.com/cgi/cp-app.cgi?usr=51H7349207&rnd=9070814&rrc=N&affl=&cip=68.243.236.77&act=&aff=&pg=prod&ref=MM-12345

    So from that I made

    w.xxxxxxxxxxxx.com/cp-app/prod/body-jewelry/MM-12345.html

    with

    RewriteRule ^cp-app/([^/]*)/body-jewelry/([^/]*)/?\.html$ shop/cgi-bin/cp-app.cgi?pg=$1&body-jewelry&ref=$2 [L]

    ________________________________________________________________

    Now I want to use the format:

    w.xxxxxxxxxxxxxxx.com/cgi/cp-app.cgi?usr=51H7349207&rnd=9070814&rrc=N&affl=&cip=68.243.236.77&act=&aff=&pg=prod&ref=MM-1234&product_name_encoded=pokemon-belly-ring

    Which I made:

    w.xxxxxxxxxxxx.com/cp-app/prod/body-jewelry/MM-12345/pokemon-belly-ring.html

    with

    RewriteRule ^cp-app/([^/]*)/body-jewelry/([^/]*)/([^/]*)/?\.html$ shop/cgi-bin/cp-app.cgi?pg=$1&body-jewelry&ref=$2&product_name_encoded=$3 [L]

    _________________________________________________________________

    So, since the old formatted links won't be there anymore, I need a way to redirect one to the other globally.
     
    theblade24, Sep 28, 2005 IP
  6. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,888
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #6
    A redirect rule would look like

    RewriteRule ^cp-app/([^.]+)/body-jewelry/(.*)\.html$ http://www.xxxxxxxxxxxx.com/cp-app/$1/body-jewelry/$2/$3.html [R=301,L]

    Except Apache would have no idea what goes to $3 since the old URL only has two changes there. Making both the old and new URLs work and only link to the new URLs are all I can think of.

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^cp-app/([^/]*)/body-jewelry/([^/]*)/([^/]*)\.html$ shop/cgi-bin/cp-app.cgi?pg=$1&body-jewelry&ref=$2&product_name_encoded=$3 [L]
    RewriteRule ^cp-app/([^.]+)/body-jewelry/([^.]+)\.html$ shop/cgi-bin/cp-app.cgi?pg=$1&body-jewelry&ref=$2 [L]

    Then as Google sees only links to the new type, the old URLs will hopefully eventually be replaced with the new ones, but still work.
     
    Nintendo, Sep 28, 2005 IP
  7. theblade24

    theblade24 Active Member

    Messages:
    84
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #7
    So you're saying keep the old method working for a period of time until all the old style links seem to be dropped the search engines?

    What about dupe content penalty for theoretically two urls having the exact same content?

    How will the search engines know which of the two links to drop if they both seemingly still work?

    Could robots.txt be setup to not allow the old style to be spidered again? That would probably hurt me huh? Might be best to let them filter off themselves?

    I would just want to be sure the one with the product name is kept.....and hopefully rank higher than the old format?

    Advice?
     
    theblade24, Sep 28, 2005 IP
  8. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,888
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #8
    If you only link to the new URLs, as they crawl the site they'll only see the new URLs. So hopefully that'll keep them from crying DC!!!!

    Unless some one figures out how to get the redirect to work, it's either both URLs working, or all of the old ones in Google all being dead and having to wait until all the new ones are indexed. Once it looks like all the old URLs are out, you can take the old version code out of the .htaccess file.
     
    Nintendo, Sep 28, 2005 IP