Search code examples
phphtmlurlhref

How to deal with a URL with the character 'é' in Safari?


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?


Solution

  • 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.