Spaces, accents and symbols in links and file names: URL encoding without broken links

Support & Account·· 52 views· 4 min read

The short answer: an address can only carry a limited set of characters. Everything else (a space, an accented letter, many symbols) travels as % followed by two hexadecimal digits: this is percent-encoding. A space becomes %20; an “é” becomes %C3%A9 (its two bytes in UTF-8). The browser does this for you and shows the readable version in the bar, which is why problems only appear when the link is copied into an e-mail, a chat, some code, or when the name belongs to a file. And some symbols have a job in the address (? # & / % +): in a file name, they break the link.

The characters that cause trouble

Character and encoding What happens if it is left as is
Space: %20 (or + in form parameters) The link is cut at the space when pasted into an e-mail or a chat. “price list.pdf” arrives as “price”.
Accented letters: é becomes %C3%A9 Usually fine in the browser, but fails in older programs, some e-mail clients and when the name was saved in another encoding: accents turning into strange symbols.
Hash: # becomes %23 Everything after it is treated as a fragment and never reaches the server: “invoice#12.pdf” gives a 404.
Question mark: ? becomes %3F The rest of the name is read as a query string.
Ampersand: & becomes %26 Inside a value, it splits the parameter in two.
Plus: + becomes %2B In the query string many programs read “+” as a space (PHP does, when it fills $_GET).
Percent: % becomes %25 A stray “%” confuses decoding.

Names and links that do not break

1 Name files before uploading them: lower case, no accents, hyphens instead of spaces, only letters, digits, hyphens and the dot before the extension. “Price List (final).pdf” becomes price-list-final.pdf. The same goes for images: alt text and file names for images.
2 Renaming a file that is already linked breaks the old link. Update the links pointing to it, or redirect the old name to the new one: 301 redirects.
3 Test the link outside the browser: paste it into a plain-text message and open it in a private window. If it is cut at a space, an accent or a “#”, it is the encoding.
4 If you write code, encode each value, not the whole address. In PHP, rawurlencode() for a piece of the path and http_build_query() (or urlencode()) for parameters. In JavaScript, encodeURIComponent() for a value and encodeURI() for an address that is already put together.
5 Do not encode twice. If a link shows %2520, the “%” of a %20 was encoded again. Fix it where the link is generated (the code, the plugin, the spreadsheet), not by renaming the file.
6 Two files that look like the same name and the site finds only one? The same accented letter can be stored in two ways (a single character, or the letter plus a separate accent mark), depending on the system the file was created on. They look identical and are not. One more reason to keep accents out of file names.
On Linux servers, the name counts letter by letter. “Photo.JPG” and “photo.jpg” are different files, and a name with a space or an accent that worked on your computer may give a 404 on the site. If an image or a PDF stopped opening after you uploaded it, compare the name in File Manager with the one in the link: error 404 on a page that should exist.
Accents in a domain name are a different mechanism (the domain is converted to a form starting with xn--), with rules of their own: accents and special characters in domain names.

A file is on the site and the link does not open it? Send us the exact link and the file name as it appears in File Manager.

Open a support ticket

SEE ALSO

The parts of a web address: scheme, domain, port, path, query and fragment

Alt text and file names for images: what to write, and what to avoid

Accents turning into strange symbols on your site: UTF-8 from file to database

Accents and special characters in domain names: what is allowed, and what to do instead

Error 404 on a page that should exist: the causes, in order

What a good page URL looks like, and how to change a bad one safely

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from $6.60/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.