Fix URL Encoding & Decoding Errors
Resolve URL encoding problems: double-encoding, broken query parameters, special character issues, and percent-encoding errors.
URL encoding issues silently corrupt data, break API calls, and cause 404 errors. Double-encoding is the most common culprit and it is almost invisible. This guide shows you how to detect and fix every URL encoding problem.
Common errors covered
Double-encoding corrupts URLs (%2520 instead of %20)
404 Not Found: /search?q=hello%2520world
The requested URL was not found (space shows as %2520)
When you encode an already-encoded URL, the % signs get encoded again: %20 becomes %2520. This happens when multiple layers of code each apply URL encoding.
Step-by-step fix
- 1 Paste the URL into our URL Encoder/Decoder and click Decode.
-
2
If you see
%20in the decoded output, it was double-encoded. - 3 Decode once more to get the original text.
- 4 Fix your code to encode only once, at the boundary where the URL is constructed.
# Double encoding - BAD
query = urllib.parse.quote('hello world') # 'hello%20world'
url = urllib.parse.quote(f'/search?q={query}') # Encodes % again!
# Encode once at the right level
params = urllib.parse.urlencode({'q': 'hello world'})
url = f'/search?{params}' # '/search?q=hello+world'
Spaces encoded as + vs %20
Search returns wrong results: looking for 'hello world' but getting 'hello+world'
There are two standards: application/x-www-form-urlencoded uses + for spaces (form submissions), while RFC 3986 uses %20 (path segments).
Step-by-step fix
-
1
Determine the context: form data uses
+, URL paths use%20. - 2 Use our URL tool to encode with the correct method.
-
3
In JavaScript:
encodeURIComponent()uses%20,URLSearchParamsuses+. - 4 Be consistent - do not mix encoding styles in the same URL.
// Using + in a URL path (wrong context)
fetch('/files/my+document.pdf') // Server looks for 'my+document.pdf'
// Use %20 in paths, + in query params
fetch('/files/my%20document.pdf') // Correct path encoding
Reserved characters breaking URL structure
URIError: URI malformed
400 Bad Request: Invalid URL
Characters like &, =, #, ? have special meaning in URLs. If your data contains these characters and they are not encoded, they will be interpreted as URL delimiters instead of data.
Step-by-step fix
- 1 Identify which part of the URL contains user data (path vs query vs fragment).
- 2 Encode user data values but NOT the URL structure characters.
- 3 Use our URL Encoder to encode individual values, then assemble the URL.
-
4
In JavaScript, use
encodeURIComponent()for values, neverencodeURI()for values.
// User data breaks URL structure const url = '/search?q=' + userInput; // If userInput = 'a&b=c', URL breaks
// Encode user data properly const url = '/search?q=' + encodeURIComponent(userInput);
Prevention Tips
-
Use URL builder libraries (
URLSearchParams,urllib.parse) instead of string concatenation. - Encode values, not entire URLs - let the URL builder handle structure.
- Test with special characters: spaces, ampersands, equals signs, Unicode characters.
- Decode and inspect URLs with our URL Encoder/Decoder when debugging.
Frequently Asked Questions
What is the difference between encodeURI and encodeURIComponent?
encodeURI() encodes a full URL but preserves :, /, ?, #, etc. encodeURIComponent() encodes everything except A-Z a-z 0-9 - _ . ~. Use encodeURIComponent for parameter values.
Why does my URL have %20 on some servers and + on others?
It depends on the encoding standard used. HTML forms use application/x-www-form-urlencoded which encodes spaces as +. URLs per RFC 3986 use %20. Both are valid in query strings; most servers accept either.
How do I URL-encode non-Latin characters?
Non-Latin characters are first encoded to UTF-8 bytes, then each byte is percent-encoded. Our URL Encoder handles this automatically.
Related Error Guides
Related Tools
Still stuck? Try our free tools
All tools run in your browser, no signup required.