views:

320

answers:

4

I noticed that various systems use various characters as the replacent for illegal ones in urls.

Is there a reason to use one or the other or should I just pick the one that looks best to me

The options I have seen so far include: - _ + and simply removing all illegal characters.

+1  A: 

I would personally use _ to replace illegal characters and - for space. One other option would be to simply remove the illegal characters.

Fredrik Mörk
Thanks for the quick reply. Is there a reason you would do it this way or is it just a personal preference?
Sruly
Using - for space seems to be rather common (as seend here at stackoverflow.com and in several blog engines). Regarding _ (or removal) for illegal characters it's only personal preference.
Fredrik Mörk
+3  A: 

Just use - for space and get rid of the illegal chars (like this site is).

Also it's all lower-case.

Dean
+1  A: 

My preference is "-" and I use a very simple RegEx to replace everything that I don't want.

[^a-zA-Z0-9\-]*

This will replace any non alpha numeric characters and dash characters with a dash.

Nick Berardi
+1  A: 

Leaving out characters can make really strange strings. Really strange strings do not help for SEO.

The 'prettiest' solution is to transliterate your non-ascii characters to their ascii-equivalent. This can be done using Iconv (if you are on a unix platform)

You could also take a look at: How to handle diacritics (accents) when rewriting ‘pretty URLs’

But that is a PHP-specific question

Hope this helps

Jacco