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
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
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?
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
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.
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.