Encoding & Escaping beginner 8 min

Fix a URL Parameter That Breaks on Special Characters

Encode query values so spaces, ampersands, and punctuation do not split the URL.

Scenario

The search link works for q=shoes and falls apart for red shoes & socks. The reason is structural: & separates parameters in a query string, so the raw value splits the URL into q=red shoes plus a phantom parameter named socks. The server sees a truncated query and the user sees wrong results. Any character with URL syntax meaning — &, =, ?, #, spaces — must be percent-encoded when it appears inside a value.

Broken input

q=red shoes & socks

Goal

Use URL Encoder to encode the parameter value — and only the value — so the special characters travel as data instead of being parsed as URL structure.

Tool sequence

  1. Open URL Encoder.
  2. Encode just the value red shoes & socks, not the whole q=... pair — encoding the = would break the parameter syntax you need to keep.
  3. Read the output: spaces become %20 and the ampersand becomes %26.
  4. Rebuild the URL as ?q=red%20shoes%20%26%20socks and confirm the boundary characters that remain (?, =) are the structural ones you meant to keep.
  5. Verify the round trip by pasting the rebuilt URL into URL Parser / Inspector — the parsed q should decode back to exactly red shoes & socks.

Checkpoint output

raw value:  red shoes & socks
encoded:    red%20shoes%20%26%20socks
final URL:  https://example.test/search?q=red%20shoes%20%26%20socks

The & now travels inside the value as %26; the server receives one q parameter containing the full phrase.

Common mistakes

  • Encoding the entire URL, which turns the structural ? and = into %3F and %3D and breaks the request a different way.
  • Leaving & unescaped inside a value, silently creating a parameter named socks that no handler reads.
  • Double-encoding an already-encoded value, turning %20 into %2520 — a literal "%20" in the search text.
  • Fixing the one link by hand instead of the URL-building code, so the next special-character query breaks the same way.

Related tools and lessons