Nested URL encoding lab · Updated November 10, 2026

Encode a URL Inside a Query Parameter Online

When a URL is itself a parameter value, encode the inner URL as data once; do not encode the outer separators that belong to the redirect URL. This preserves the inner ?, &, and = instead of accidentally turning them into outer parameters.

What changes at each layer

LayerObserved valueWhy it matters
Inner URLhttps://example.com/search?q=a%20b&tag=redIts ampersand separates inner parameters.
Outer parameter valuehttps%3A%2F%2Fexample.com%2Fsearch%3Fq%3Da%2520b%26tag%3DredThe inner URL is now one escaped value.
Outer URL...?returnTo=...Only the outer ? and & remain structural.

Common failure: encoding the wrong layer

If you concatenate the raw inner URL after returnTo=, its &tag=blue becomes a second outer parameter. If you encode the complete outer URL again, the redirect endpoint may receive a literal %3F instead of a query separator. Parse the outer query first, then decode its returnTo value once.

Measured round trip

The browser tool below uses the platform URL parser. It records the raw outer query, the encoded value, and the decoded inner URL so you can see whether each layer survives.

FAQ

Should I encode the inner URL twice?

No. Encode it once when assigning it as the outer parameter value. A second decode or encode changes literal percent signs and can create a different URL.

Do fragments belong in the request?

No. A fragment stays client-side. If it is part of the inner URL, it is still data inside the encoded parameter.

For general component encoding, use the URL Encode tool. For query parsing, see Query Parameters.