I am trying to create a clean URL using a RewriteRule in an .htaccess file (using Apache 2.2).
Using a hypothetical example, I would like this:
Ripley’s Believe It Or Not – Piccadilly Circus (London, England)
To appear like this:
i.e. Remove all punctuation, replace spaces with hyphens, and make upper case letters lower case. The number of spaces will vary from entry to entry and could be even more than the eight here, so I expect the [N] suffix may well be required.
I am currently using the ‘id’ (below) rather than the ‘attraction_name’, which is obviously far simpler, but does not create a very useful or attractive URL:
I have also used a PHP custom function (‘GenerateUrl’) to generate the URL I need from within the link (below), but with this method (found at this site) the variable is not passed to the next page in its original state and therefore cannot then be used to select corresponding data.Code:Options +FollowSymLinks RewriteEngine on RewriteRule ^attraction/([0-9]*)$ attraction/?id=$1 [L,NC,QSA]
I don’t want to use the ‘RewriteMap myquery’ method as once my site goes live I don’t expect I’ll have access to the server’s httpd.conf or virtualhost configuration files, which that would require.PHP Code:
<a href = "/attraction/<?php echo GenerateUrl($attraction['id']); ?>"><?php echo html($attraction[attraction_name']); ?></a>
I’ve considered using the custom function to create a URL that can be saved in the ‘attraction’ table and therefore be used to select corresponding data thereafter, but would rather not given I’m pretty sure it’s avoidable.
I just can’t figure out what the RewriteRule should be – can anybody help me out?
<snip><merged from hijacked thread><edited>
DK or ScallioXTX seeing as you each seem to be have expertise on RewriteRules, I hope that you might be able to help.
Thanks in advance,