Results 1 to 11 of 11
Nov 20, 2012, 14:41 #1
- Join Date
- Jun 2012
- London, United Kingdom, United Kingdom
- 0 Post(s)
- 0 Thread(s)
.htaccess RewriteRule clean URL (remove punctuation; replace spaces with hyphens,etc)
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:
Options +FollowSymLinks RewriteEngine on RewriteRule ^attraction/([0-9]*)$ attraction/?id=$1 [L,NC,QSA]
<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,
Last edited by ServerStorm; Nov 20, 2012 at 15:20.