A query string is a small contract between a link and a server. The server splits the string at agreed punctuation marks and reads each value that falls out. That contract holds only while the values keep their side of it: the moment a value contains one of the punctuation marks itself, an ampersand in a search term, a question mark in a return address, the split happens in the wrong place and later parameters shift or vanish.
The safe way to build a query string is boring, and that is its strength. Encode every value separately, before assembly, and let the punctuation stay punctuation. This guide shows how, using the free URL Encoder/Decoder on Ovatly in Component mode.
Contents
- Quick answer
- What a query string is made of
- The one rule: encode values, never the string
- Spaces: %20, plus signs, and form submissions
- Values that contain whole URLs
- How to build a query string, step by step
- Worked example: a two-parameter search link
- Limitations and honest warnings
- Common mistakes
- FAQs
- Conclusion
Quick answer
Encode each value on its own, then assemble. For every value, open the URL Encoder/Decoder, choose Component mode, paste the value, and press Encode. Component mode encodes everything a URL cannot carry raw, including &, =, ? and /. Join the results with a raw ? before the first parameter and raw & characters between parameters, and never encode the whole string at once: the separators are structure and must stay raw.
What a query string is made of
A query string has two kinds of content. The structure is three characters: ? opens the query string, & separates one parameter from the next, and = separates a parameter's name from its value. Everything else is data: the names, usually short plain words, and the values, which come from users and can contain almost anything.
Trouble starts when data impersonates structure. A value holding a raw & looks, to the server, like two parameters. A value holding a raw ? or = blurs the name and value boundary. Percent-encoding is how data stops impersonating structure: each unsafe character is replaced by a % followed by two digits, a form that carries the character as data and can never be mistaken for punctuation.
The one rule: encode values, never the string
Encode each value separately, in Component mode, and assemble afterwards. The order matters. Encoding after assembly cannot be done safely, because by then values and separators are mixed in one line of text, and no tool can tell a structural & from one inside a search term.
The entry for the tool states the split plainly: if you are building one value inside a URL, like a search term or a redirect target, use Component mode. If you have a whole address with a space in it, use Full URL mode instead, which encodes spaces and stray characters while leaving structural characters alone. The two modes exist precisely because values and whole addresses need opposite treatment of the same characters.
Parameter names rarely need encoding, since they are normally plain words of letters and digits. Values are where the risk lives, so encode them every time, even when a value looks harmless. Making it a habit removes the judgement call.
Spaces: %20, plus signs, and form submissions
Spaces are the most common unsafe character, and they have two written forms. In query strings produced by form submissions, a + means a space: the convention of the form encoding browsers use when sending a form. Outside that context, the unambiguous form is %20. This tool uses %20, which is valid everywhere in a URL, to avoid ambiguity.
A hand-written + can be read as a space by a form-style parser and as a literal plus sign by everything else. If a value genuinely contains a plus sign, encode it: Component mode turns it into %2B, which every reader decodes back to a plus. Encoding settles the question.
Values that contain whole URLs
The strictest test of the rule is a value that is itself an address: a return or redirect parameter carrying the page to return to. Such a value contains /, ?, = and &, every structural character there is. Left raw, its inner & splits the outer query string and its inner ? blurs the outer boundary.
Component mode was built for exactly this. It encodes all four characters, so the inner address collapses into a single inert value that the receiving page can decode and use whole. A long encoded block full of %2F and %3F in a real link is usually a nested address being carried safely, not corruption.
How to build a query string, step by step
- List the address and parameters, with values in their plain, human form.
- Open the URL Encoder/Decoder and choose Component mode.
- Paste the first value, press Encode, and set the result aside.
- Repeat for each remaining value. One value per pass, never the whole string.
- Assemble the link: the address, a raw
?, thenname=encoded valuepairs joined by raw&characters. - Test the finished link and check that each value arrives whole.
Worked example: a two-parameter search link
Suppose you are building a link to a search page with two parameters: a search term, q, whose value is red shoes & socks, and a return address, return, whose value is /cart?step=2&done=yes.
Encode the search term first. In Component mode it becomes:
red%20shoes%20%26%20socks
The spaces are %20 and the ampersand is %26, so the term can no longer split the string. Now encode the return address:
%2Fcart%3Fstep%3D2%26done%3Dyes
Every structural character in the inner address is now a code: %2F for /, %3F for ?, %3D for =, %26 for &. Assemble the two encoded values with raw separators:
https://example.com/search?q=red%20shoes%20%26%20socks&return=%2Fcart%3Fstep%3D2%26done%3Dyes
Read the result the way the server will. It splits on the raw & and finds exactly two parameters, because the only raw & in the string is the separator. It decodes q back to red shoes & socks and return back to /cart?step=2&done=yes, complete with its own query string intact.
Limitations and honest warnings
Encoding guarantees safe transport, not correct values. A perfectly encoded link can still carry a misspelled search term, a return address that no longer exists, or a parameter name the page does not recognise.
Encoding is not encryption, either. Anyone who sees the link can paste a value into this same tool and read it in plain text, so query strings are the wrong place for anything sensitive, encoded or not.
Expect growth. Each unsafe character becomes three characters, and non-ASCII characters take more, since they are encoded as their UTF-8 bytes: café becomes caf%C3%A9. Long values can swell noticeably; that is normal, not an error.
When you need to inspect a link someone else built, decode its values one at a time. The tool reports a clear error on invalid input, like a stray % or an incomplete %2, instead of guessing: a sign the value was damaged.
Common mistakes
- Encoding the whole query string in one paste. The separators get encoded along with the values, and the server receives one giant value instead of separate parameters. One value per pass, always.
- Using Full URL mode for a value. That mode deliberately leaves
&,?and/alone, so the value keeps the exact characters that break query strings. Values belong in Component mode. - Encoding a value twice. A second pass turns
%into%25, and the server decodes the value back to the encoded text instead of the original. Encode once, at build time. - Writing + for spaces by hand. In a hand-built link,
+is a gamble about which parser will read it. Use%20, and encode a genuine plus sign as%2B.
FAQs
Should I encode the whole query string at once?
No. Encode each value separately. The ? and & between parameters are structure, and encoding them turns them into data and breaks the string. Component mode is for one value at a time.
Can a value contain a whole URL?
Yes, once it is encoded. Component mode encodes /, ? and &, so a return address like /cart?step=2&done=yes becomes a single safe value: %2Fcart%3Fstep%3D2%26done%3Dyes.
Is + the same as %20?
In query strings produced by form submissions, + means a space. This tool uses %20, which is valid everywhere in a URL, to avoid ambiguity.
Why did my encoded text get longer?
Each unsafe character becomes three characters, like %20 for a space. Non-ASCII characters take even more, since they are encoded as their UTF-8 bytes.
Which mode do I need? If you are building one value inside a URL, like a search term or a redirect target, use Component. If you have a whole address with a space in it, use Full URL.
Conclusion
A safe query string is assembled, not written: values encoded one at a time in Component mode with the URL Encoder/Decoder, separators left raw, nested addresses encoded like everything else. Build links that way and they arrive whole. When a link built the other way reaches you already broken, the repair follows the same diagnosis in reverse, as How to Fix Broken Links Caused by Unencoded Characters shows. For more tools like these, see the Developer Tools guide archive.