What char should be used to replace illegal characters in a url

I've noticed that different systems use different characters as surrogate characters for illegal 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've seen so far include: - _ + and just remove all illegal characters.

0


a source to share


4 answers


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



And it's all in lower case.

+3


a source


I would personally use _ to replace illegal characters and - for whitespace. Another option is to simply remove the invalid characters.



+1


a source


My preference is "-" and I use a very simple RegEx to replace anything I don't need.

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

      

This will replace any non-alphabetic numeric characters and dash characters with dashes.

+1


a source


By leaving characters alone you can make really weird strings. Indeed, strange lines don't help SEO.

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

You may also want to take a look at: How to handle diacritics (accents) when rewriting "good URLs"

But this is a PHP specific question

Hope it helps

+1


a source







All Articles