When you type an address or click a link, the URL is percent-encoded before it leaves the browser, and it is decoded again on the server. Most of the time this is invisible. When it is not, the symptoms are files that cannot be found, plus signs that turn into spaces, and security filters that can be bypassed. This guide follows a URL through one request.
What the browser sends
Take this address:
https://example.com/files/Q3%20report.pdf?q=caf%C3%A9+au+lait&tag=a%26b#page=2The browser connects to the host and sends a request line containing only the path and the query, still encoded:
GET /files/Q3%20report.pdf?q=caf%C3%A9+au+lait&tag=a%26b HTTP/1.1
Host: example.comThe fragment, #page=2, is not sent. It stays in the browser for scrolling and for client-side code.
How the server decodes it
A server or framework must split the target into its parts before decoding, because decoding first would turn an encoded %3F into a real ? and move the boundary between path and query. Then it decodes each part:
- Path: plain percent-decoding.
/files/Q3%20report.pdfbecomes/files/Q3 report.pdf. A+in a path stays a plus. - Query: most frameworks parse it with the form rules from the WHATWG URL Standard, where
+means a space. Parsed that way, this query gives:q=café au laittag=a&b
%26insidetagstays part of the value because the query was split on&before decoding.
Decode once, at the right time
RFC 3986 says implementations must not percent-encode or decode the same string more than once. Decoding twice is not just a correctness bug. OWASP describes double encoding as a way past security filters: a path such as %252E%252E%252F looks harmless after one decode (%2E%2E%2F), but becomes ../ if a later layer decodes it again (OWASP: Double Encoding). Validate input after the final decode, and decode in exactly one place.
When things go wrong
- 404 for a file with a space or plus in its name. The link was not encoded, or was encoded with form rules (
+) for a path. Paths need%20; see %20. - 404 for a path containing %2F. Several servers reject encoded slashes in paths by default; see %2F.
- A + in a query value becomes a space. Form-style parsing at work; encode a literal plus as %2B.
- 414 URI Too Long. The URL exceeded a server limit. RFC 9110 recommends supporting at least 8000 octets, but proxies and servers set their own limits; move large data into the request body.