0

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.

Sruly
  • 10,200
  • 6
  • 34
  • 39

4 Answers4

3

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

Also it's all lower-case.

Dean Rather
  • 31,756
  • 15
  • 66
  • 72
1

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
  • 155,851
  • 29
  • 291
  • 343
  • Thanks for the quick reply. Is there a reason you would do it this way or is it just a personal preference? – Sruly May 18 '09 at 13:00
  • 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 May 18 '09 at 13:03
1

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
  • 54,393
  • 15
  • 113
  • 135
1

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

Community
  • 1
  • 1
Jacco
  • 23,534
  • 17
  • 88
  • 105