Too large htaccess file, need script for rewrite?

Discussion in 'Apache' started by theblade24, May 4, 2006.

  1. #1
    I have asked this question before......and the answer for a universal mod rewrite I guess created an endless loop or whatever and it wouldn't work, unless the rule was just wrong.

    But I have about 7000 products, hence 7000 urls that I was rewriting a certain way and then changed the method of rewrite to include the item name in the url and shorten the url so it didn't appear that the page was deep in several directories. So I began rewiting them a different way. It now looks like they are top level pages. The jest of this is I'm trying to 301 redirect all of them to their new style.

    domain/cp-app/prod/sports-memorabilia/ItemID is now set to display as

    domain/sports-memorabilia-Item-Name--ItemId.html

    I made a 301 rewrite rule for each and every one to redirect them, and I think it worked, but that meant putting 7000 or so lines in my htaccess file and it ballooned to 1.5 meg in size and slowed my dynamic site to a crawl. I quickly abandoned that method.

    Does anyone know of a rewrite or redirect method that would work? I read briefly on webmasterworld something about a script or external from the htaccess file to accomplish this but didn't understand it at all.

    The bottom line is I am trying to redirect 301 a url that has been written one way to rewriting it another way. If anyone has methods or suggestions I would really really appreciate their help. If it involves a coding or script or something I am willing to pay someone for their time.

    I know I am not the first person who has ever changed the method of rewrite they are using for alot of urls. There must be a method that can solve this issue. I hope someone out there has the knowledge and experience to put me on the right track.

    Thanks in advance for your time and help!!
     
    theblade24, May 4, 2006 IP
  2. chengfu

    chengfu Well-Known Member

    Messages:
    113
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #2
    7000 rules? Wow, impressive. How much time does it take to produce something like that?

    Probably something like this will work for you:
    
    RewriteRule ^/[a-zA-Z0-9-]+--([0-9]+).html$ /shop.php?itemId=$1 [L]
    
    Code (markup):
    This will pick the ItemID from the url and call shop.php with the itemid as a parameter.
     
    chengfu, May 4, 2006 IP
  3. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #3
    Post a few original URLs of some products, how they were, and how you want them!!! Odds are 99.9999% that you only need one line for them, and one line for the 301!!! :eek:

    How slow were the pages loading with that lany lines!! :eek:
     
    Nintendo, May 4, 2006 IP
  4. theblade24

    theblade24 Active Member

    Messages:
    84
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #4
    Old rule and url

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

    http://www.xoxoxoxoxox.com/cp-app/prod/sports-memorabilia/HM-PHOTO323K

    cp-app is the cgi script, prod is the page (short for product), sports-memorabilia is just a fake dir to put those keywords in the url, ref is the item ID
    ---------------------------------------------------------------------
    New rule and url

    RewriteRule ^sports-memorabilia-(.*)\.html shop/cgi-bin/cp-app.cgi?seo=item--$1 [L]

    http://www.xoxoxoxoxoxo.com/sports-memorabilia-Jason-Varitek-Gold-Coin-Photomint--HM-PHOTO323K.html

    Top level page now, sports-memorabilia is again just fake keywords inserted, Jason Varitek Gold Coin Photomint is the items name or <Title> tag, HM-PHOTO323K is the itemID, and of course it now has html added to the end

    I need to 301 redirect anything formed in the top version if someone hits a spidered link to the new version method.

    I hope its doable.
     
    theblade24, May 5, 2006 IP
  5. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #5
    Your first one has two ([^/]*), where do they both go in the new URL??!!

    Did all the URL's have /prod/ there?
     
    Nintendo, May 5, 2006 IP
  6. theblade24

    theblade24 Active Member

    Messages:
    84
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #6
    All have prod for product.

    The one before sports-memorabilia is the word prod

    The one after sports-memorabilia is the product id.

    The only one of those two used in the second method is the product id.

    Here is where it gets tricky. The item id stays the same in both urls but in the new style second one it actually relies on a routine in the cgi script to pull the title tag from an sql db, strip bad characters etc etc and add it to the url before it actually spits out the url.

    I don't know if the first one can be redirected to the second one and still have it perform that function?
     
    theblade24, May 5, 2006 IP
  7. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #7
    RewriteRule ^cp-app/([^.]+)/sports-memorabilia/([^.]+)/?$ http://www.domain.com/sports-memorabilia-$2.html [R=301,L]

    If this doesn't do anything, you're toast.
     
    Nintendo, May 5, 2006 IP
  8. OoKami255

    OoKami255 Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Yeah. HoLY Cripes man! 7,000 rewrite rules?! Simplify! Always keep things simple, in math or real life. ;)

    Good luck, you'll need it.
     
    OoKami255, May 5, 2006 IP
  9. theblade24

    theblade24 Active Member

    Messages:
    84
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #9
    Does this go before the other two rules? after the other 2? In between?

    remove 1st rule, leave second.....???
     
    theblade24, May 6, 2006 IP
  10. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #10
    Replace

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

    with that new code, and hope you're not toast!!!!
     
    Nintendo, May 6, 2006 IP