如何在Safari中处理带有“é”字符的URL?

I have files that I need to open/download from my webpage using links in a menu. My problem is when I try to open a file that has an 'É' in it with Safari (7.0.1). It's working with Firefox 26.0, Chrome 32.0.17 and IE.

The name in the URL is correct but the Not Found error shows a complete different name.

In the URL: FORMULAIRE%20-%20ENVOI%20DE%20MESSAGE%20PAR%20TÉLÉCOPIEUR.doc

The page error:

FORMULAIRE - ENVOI DE MESSAGE PAR TÉLÉCOPIEUR.doc was not found on this server.

I tried urlencode(), rawurlencode(), htmlspecialchar() and my page's charset is set to UTF-8.

I absolutely need to keep the accents in the file's name. Someone have an idea?

A handy workaround for dealing with tricky characters in URLs is to use their percent-encoded values. In this case I believe you'd need to pass %C3%89 in place of the É, just like passing a %20 in place of a space.

So try this:

FORMULAIRE%20-%20ENVOI%20DE%20MESSAGE%20PAR%20T%C3%89L%C3%89COPIEUR.doc

It sounds like you're on a Mac, but if you have access to a Windows machine (vm or otherwise) Fiddler is a great swiss-army knife for all things HTTP, and it's tool menu includes a "Text Wizard" which can help with lots of text encoding/decoding.

You can't have accented characters in a URL. Only ASCII characters are permitted. See more info at http://tools.ietf.org/html/rfc3986#section-2

It's possible to rewrite URL's to handle accented characters, unfortunately I'm not up to scratch with URL Rewriting so I can't provide that for you - but it is possible.

You probably have the page in your local encoding and safari has some bug inside. You need to help the webbrowser by urlencoding, which seem to not work in php correctly. You have to replace those characters manually. It will depend on your locale (it seem to be french or something like that). See the strtr function in php and use association array from the characters in your locale to %xx/%xx%xx representation... That is the only thing you can do (except using UTF instead of the french encoding.)

Just met the same issue with safari, we found that the root cause is related to the unicode normalization form

  • In safari, it's using NFC normalization form, so is normalized to code point: 0019

  • while in chrome, it's using NFD normalization form, so is normalized to 2 code points: 0045, 0301

another example from wiki enter image description here

To handle this issue, the server side need to keep the strings in same unicode normalization form before using it. And it's better to avoid using these characters in URL