Home     Articles & Projects     Products & Web Services

htaccess query

Hi.

I am trying to tidy up some php urls on one of my sites

e.g. http://www.gocaravanning.com/details/parkdetails.php?Name=Devon Cliffs Holiday Park&Urn=635

to show as http://www.gocaravanning.com/details/Devon_Cliffs_Holiday-Park-635.html

I have managed to get it to work as follows

http://www.gocaravanning.com/details/Devon%20Cliffs%20Holiday%20Park-635...

Is there a way in the htaccess file to change the %20 to be _ for example

Here is the htaccess I am using

RewriteEngine on
RewriteRule ^(.*)-(.*).html$ parkdetails.php?Name=$1&Urn=$2 [L]

Any help would be great

Many thanks

Simon

Hi Simon, %20 is being

Hi Simon,

%20 is being inserted by the browser as the URL encoding of the space character, so the only way to avoid that being shown in the URL to is to use something as a substitution for space in your code, both where you generate the URLs and then where you use them.

In Price Tapestry, this is done using a hyphen (see tapestry_hyphenate() in includes/tapestry.php) when generating the URLs, for example in search.php where the search results are displayed. Then, at the top of the script that is the target for the rewrite URL, the opposite translation is applied; so let's say you pass the value through in the $q variable ($_GET["q"] strictly speaking), then you could process it at the top of your script as follows to revert to the original value;

$q = str_replace("-"," ",$q);

If the name is available available in whatever you are querying based on the URN that step may not be necessary and you can simply use the name value from the database...

Hope this helps!
Cheers,
David.