decodeurl.com

Article

BLOG

When Should I Encode `/`, `?`, and `#` in a URL?

How slashes, question marks, and hash signs change meaning depending on whether they are syntax or data.

Slashes, question marks, and hash signs are not always errors in URLs. They are structural characters. The question is whether they are acting as URL syntax or as literal data inside a value.

When those characters are data, encode them with the URL Encode tool. When reading a strange link, use the URL Decode tool to see what was intended.

When should I encode / in a URL?

Encode / as %2F when the slash is part of a single value, such as an ID, filename, or redirect parameter. Leave / unencoded when it is meant to separate path segments in the URL structure.

When should I encode ? in a URL?

Encode ? as %3F when it appears inside data, such as a search phrase or nested URL. Leave the first real ? unencoded when it starts the outer URL's query string.

When should I encode # in a URL?

Encode # as %23 when it is part of a value. A real unencoded # starts the fragment, and anything after it may not be sent to the server, which can silently remove data from requests.

Why is an encoded slash sometimes dangerous in paths?

An encoded slash can be dangerous in paths because some servers, proxies, and routers decode %2F before routing or reject it entirely. If a value may contain slashes, putting it in a query parameter is often more predictable than using it as a path segment.

What happens if I encode the structural slash?

If you encode a structural slash, the URL path changes meaning. /products/paper has two path segments, while /products%2Fpaper has one encoded segment. Some routers treat those as different resources.

How do I know whether a character is syntax or data?

Ask whether removing or changing the character would change the URL's structure. If /, ?, or # separates URL parts, it is syntax. If it belongs to a user value, title, filename, or nested URL, it is data and should be encoded.

What is the safest rule for manual links?

Build the URL structure first, then encode each inserted value separately. The URL Encode tool is meant for those values, not for blindly encoding every character in a complete finished URL.

← Back to the blog