Hey, I’m encountering a problem which I can’t imagine hasn’t been fixed before by someone else.
For my website I am using htaccess to rewrite the urls, transforming for instance:
index.php?section=therapists&item=Therapist
to
therapists/therapist.html
Now I’ve been putting off handling non-alphanumeric characters by simply using urlencode (so therapist name would become therapist+name), but now I want to go and implement it.
What I would like would be replacing every symbol that is not alphanumerical to dashes, or at least all the spaces. Now my problem is that if I have the following name: Just a-test, this would be rewritten to just-a-test.html and when I take this variable from the $_GET and after str_replacing the dashes try to look for “just a test” in the database, I won’t find it.
Of course I could replace the dashes to underscores, but then I would have the same problem with underscores, etc etc.
How do you (or most people) handle this? I could put the item’s id in the url as well but I really don’t want to (I only do that if the name occurs multiple times).