Skip to main content

Guides Β· Developer Tools Β· 3 min read

Encoding and Decoding URLs Correctly

URLs are structured strings, and structure needs escaping rules. Encode wrongly and parameters split, routes misroute, and search queries arrive mangled; the symptoms appear far from the cause, which is what makes these bugs notorious.

Filorra’s encoder/decoder handles both modes locally in your browser, so debugging a production link never requires pasting tokens or internal URLs into external services.

Quick answer

Encode each value with component encoding when building URLs; decode exactly once at the point of consumption. Reserved characters (?, &, #, /, %) and spaces inside values are the triggers; %2520 in a URL means something was encoded twice.

Step by step: Encoding and Decoding URLs Correctly

  1. Identify what is data and what is structure

    In https://example.com/search?q=cats&sort=new, only cats and new are data; everything else is syntax. Data gets escaped; syntax does not.

  2. Apply component encoding to each value

    Encode individual values (encodeURIComponent-style): spaces become %20, ampersands %26, slashes %2F. Assemble the full URL afterwards, joining with unencoded ?, &, and =.

  3. Decode once, at consumption

    The receiving side decodes each parameter value exactly once before use. Early decoding invites injection; late or double decoding produces %xx literals in output.

  4. Round-trip test suspicious links

    Paste problem URLs into the encoder/decoder and decode then re-encode: what you get back reveals how many times and in which mode the original was mishandled.

The two modes and their failure signatures

Component mode escapes everything unsafe including & = / ?. Full-URL mode preserves those structural characters. Component-encoding a whole URL yields %3A%2F%2F soup; full-URL-encoding a bare value leaves & unescaped and splits parameters. Matching mode to job fixes both syndromes instantly.

Libraries name these differently but the dichotomy is universal: escape-a-value versus escape-but-keep-syntax. When reading unfamiliar code, identifying which mode runs is the entire comprehension task.

Double-encoding: the gift that keeps giving

%2520 is the fingerprint of double encoding: % got escaped (%25) along with the rest. It happens when frameworks auto-encode values already encoded upstream, or when developers defensively encode at multiple layers.

The cure is architectural: encode exactly once, at the boundary where data enters URL context, and treat decoded strings as final thereafter. Audit chains when %25 sequences appear; somewhere, a layer is redundant.

Common mistakes

Encoding plus signs blindly in query strings
+ means space only in legacy form encoding contexts; elsewhere it is a literal plus needing escape (%2B). Know which context you are in before converting spaces.
Building URLs by string concatenation of raw user input
Raw input smuggles & and # into your structure. Every interpolated value passes through component encoding, no exceptions, especially "temporary" debug code.
Decoding in middleware for all downstream consumers
Global early decoding breaks components expecting encoded input. Decode where the value is used, not where it arrives.

Privacy and security

Encoding and decoding run in-browser; authenticated URLs and tokens under inspection never leave the device.

Frequently asked questions

Do I need to encode base64 values in URLs?
Yes when using standard base64: its + and / clash with URL syntax. Use the URL-safe variant (- and _) or component-encode the standard output.
Why does my framework seem to encode automatically sometimes?
Many layers (template engines, HTTP clients, routers) apply encoding opportunistically. Map which layer encodes what, or you will fight phantom double-encoding forever.
All questions β†’
All guides β†’
All articles β†’