A URL that works fine in one place silently breaks in another. Links return 404 errors. API calls fail with no clear message. Email links don't open the right page. In most cases, the cause is the same: special characters in a URL that weren't properly encoded. Here's how to identify the problem and fix it.
Why URLs Break: The Root Cause
URLs have a strict character set. Only letters (A–Z, a–z), digits (0–9), and a small set of characters (- _ . ~) are considered "unreserved" and safe in any URL position. Everything else is either reserved (has a specific structural role) or disallowed.
When you include a character like a space, ampersand, or quote in a URL without encoding it, different systems handle it differently — some strip it, some misparse the URL, some return an error. The URL looks fine to you but breaks when transmitted.
The Most Common Culprits
These are the characters most likely to break a URL if not encoded:
- Spaces: Must be encoded as
%20(or+in query strings). A space in a URL is often silently dropped or causes a parse error. - Ampersand
&: Separates query parameters — if your parameter value contains an &, it must be encoded as%26or the URL splits in the wrong place. - Equals sign
=: Separates parameter names from values — if it appears inside a value, encode it as%3D. - Hash
#: Marks a page anchor — if used inside a query parameter, it must be encoded as%23or the browser treats everything after it as a fragment identifier. - Non-ASCII characters: Accented letters, Cyrillic, CJK characters — these must be UTF-8 encoded then percent-encoded (e.g., ü →
%C3%BC).
Real-World Scenarios
Scenario 1: Email campaign link breaks. You add a UTM campaign name like Spring & Summer Sale. The & splits the URL into two parameters. Fix: encode the campaign name as Spring%20%26%20Summer%20Sale.
Scenario 2: File download URL returns 404. A file named Q&A Guide (2025).pdf has spaces and parentheses. The server can't find the file because the URL wasn't encoded. Fix: rename the file to qa-guide-2025.pdf or encode the filename as Q%26A%20Guide%20%282025%29.pdf.
Scenario 3: API call fails silently. A search parameter contains a user-entered string with special characters. The API receives a malformed query. Fix: URL-encode the parameter value before appending it to the endpoint URL.
Step-by-Step: How to Fix a Broken URL
- Identify the problematic characters. Look for spaces, &, =, #, ?, /, %, non-ASCII characters in the wrong positions.
- Determine which part of the URL they appear in. Path segments, query parameter names, and query parameter values all have slightly different encoding requirements.
- Encode the characters. Use a URL encoder tool — paste the string and get the encoded version. For parameter values, encode only the value, not the surrounding structure (
?q=stays as-is, only the value after=gets encoded). - Test the fixed URL. Paste it into a browser or test with curl/wget. Verify you get the expected response.
Preventing Broken URLs: Best Practices
The best fix is prevention. Follow these rules when constructing URLs:
- Never build URLs by raw string concatenation — use URL builder libraries in your language (Python's
urllib.parse, JavaScript'sURLSearchParams, etc.) - Keep file names URL-safe: lowercase, hyphens instead of spaces, no special characters
- For UTM parameters: encode values before appending — especially campaign names with spaces or special characters
- When copying URLs from browsers: use the address bar's "copy link" rather than copying from HTML source — browsers display decoded URLs but links in source may have issues
Try the Free Tool
Paste a broken URL to encode special characters, or decode a percent-encoded URL back to readable text.
Fix Your URL →Frequently Asked Questions
Why does my URL show %20 instead of a space?
%20 is the URL-encoded representation of a space. When a URL contains a space, browsers and systems encode it as %20 to make it safe for transmission. If you see %20 in your browser's address bar, it's functioning correctly — the server receives and decodes it as a space.
How do I encode a space in a URL?
Replace spaces with %20 in any URL component. In HTML form query strings (GET method), spaces can also be represented as + (a plus sign). %20 is universally correct; + works only in query strings, not URL paths.
What causes a URL to return a 404 error when it looks correct?
Common causes: special characters in the URL that weren't encoded (spaces, &, #), case sensitivity on the server (URLs are case-sensitive on Linux servers), or a filename/path mismatch. Check the URL encoding first — that's the most common and easiest fix.
Can I URL encode an entire URL at once?
Be careful here. If you encode an entire URL including the structural characters (://, /, ?, &, =), the URL itself breaks because those delimiters get encoded too. Only encode specific components: path segments or query parameter values. Use a URL encoder tool that lets you specify what to encode.
Do I need to encode URLs when sharing links on social media?
Usually no — modern browsers and social platforms handle encoding automatically when you paste a URL. The exception is URLs with non-ASCII characters (like Arabic or Chinese text in paths) or manually constructed UTM parameters where you've included special characters in campaign names.