Forum Moderators: phranque
The php script I use for a place page is viewplace.php and it uses the ID for the town to determine what town it is displaying.
viewplace.php?id=1234
But I wanted nice url's like...
places/England/Gloucestershire/Watermead
I Wrote a simple php script to create the .htacess entries. It wrote them to a text file
RewriteRule ^places/England/Gloucestershire/Watermead$ places/viewplace.php?place=224
RewriteRule ^places/England/Cumbria/Watermillock$ places/viewplace.php?place=223
RewriteRule ^places/England/Gloucestershire/Watermoor$ places/viewplace.php?place=222
RewriteRule ^places/England/Cambridgeshire/Water_Newton$ places/viewplace.php?place=221
It was then a simple case of copy paste to my main .htacess file the problem being my .htacesss file now has 48485 lines, and even on localhost page load times are around 4 seconds.
Does anyone have any suggestions on how to work round this? Regex doesn't look like an option because there is nothing regular about the entries
Thanks in advance.
Mack.
RewriteRule ^places/([^/]+)/([^/]+)/([^/]+)$ places/viewplace.php?country=$1&county=$2&town=$3 [L]
All that would be needed is for you to add a field to the town table with the country, county & town concatenated (with maybe a colon between each so there's no chance of dupes).
e.g.
England:Cumbria:Watermillock
Now index that field and you can look that up instead of the integer (but you could return the integer if other parts of the script require it) - remember that you have 3 parameters to pull in.
You can use that to call a script during the URL-to-filename translation phase of the Apache API, and then rewrite to the result of that lookup.
Generally, the script called by using a RewriteMap will be written in PERL, but it could be anything that can support reading your database. Be very careful, though; This script must never be allowed to 'die' because only one instance of this script is ever started or executed. If it dies, your server(s) won't work.
RewriteMaps must be defined at the server config level, but can then be accessed by mod_rewrite code in both server config files and in .htaccess files.
Jim