Mod_rewrite for over 4000 listings?

Discussion in 'Apache' started by Mulith, Jan 20, 2009.

  1. #1
    I'm still quite early on in the process of learning how mod_rewrite works and I'm a little confused about how to implement it for our 4000+ listings.

    Here is an example of one of our listings:
    http://www.business4sale.co.uk/View_Listing.php?id=5192

    I want it to look like this:
    http://www.business4sale.co.uk/London/Well_Established_Profitable_Restaurant_For_Sale.php (or.html)

    The part after ".co.uk/London/" needs to be the same as the page's title($headline) which is pulled from our database and the "/London/" part needs to be the "city" variable in our database so something like this:

    /$city/$headline .php or .html

    I'm not even sure if this is possible but it would be great for displaying relevant content to searchers on the SE's.


    Please see the following URL which shows how one of our competitors does it:
    http://uk.businessesforsale.com/uk/Freehold-Public-House-In-Ilfracombe-For-Sale.aspx

    Any advise or help would be great. Thank you
     
    Mulith, Jan 20, 2009 IP
  2. fava

    fava Peon

    Messages:
    26
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What you want is the Rewritemap command.

    It will allow you to create a textfile/database of rewrite rules which will be processed quickly.

    For 4000+ rules I suggest using the hashfile type.

    See http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteMap for more info.

    fava
     
    fava, Jan 20, 2009 IP
  3. mortenb

    mortenb Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    fava is right
    A rewritemap is definitely the way to go here
     
    mortenb, Jan 20, 2009 IP
  4. whose

    whose Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Wow. I had never heard of Rewritemap.

    How does it differ or is better than using a similar mod_rewrite instruction in an .htaccess file?
     
    whose, Jan 21, 2009 IP
  5. fava

    fava Peon

    Messages:
    26
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    mod_rewrite would require a 4000 line .htaccess file, one line per rewrite.

    I don't think that .htaccess is cached (will someone correct me if I am wrong), so every pageload would require parsing 4000 lines of code, the lookup would then need to search though at least half of them to find the correct one.

    Using hashmap requires 1 line in the .htaccess file and lookups will be faster as well because it is indexed.

    fava
     
    fava, Feb 2, 2009 IP
  6. Mulith

    Mulith Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I see what you mean. To be honest I am pretty new to this rewrite stuff.

    Is anyone able to setup rewritemap for a fee on our site? That way I can learn while ensuring it is done right.
     
    Mulith, Feb 10, 2009 IP
  7. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #7
    Not if the ID number is in the URL.

    Options +FollowSymLinks +Indexes
    RewriteEngine on
    RewriteBase /
    RewriteRule ^London/([^.]+)/([^.]+)\.html$ View_Listing.php?id=$1 [L]

    would cover every URL.

    business4sale.co.uk/View_Listing.php?id=5192
    business4sale.co.uk/London/5192/Well_Established_Profitable_Restaurant_For_Sale.html

    being the same thing. Editing the script to make the links look like that is the next thing to do. Only if you're a good enough php programmer, can you get the script to call it with out having the number in the URL.
     
    Nintendo, Feb 10, 2009 IP