URL encoding turns characters such as spaces, ampersands, and non-ASCII text into a form that can travel safely through a web address. This guide provides a practical checklist for encoding query parameters, preserving UTM tracking, avoiding double-encoding, and debugging links that are truncated, misread, or redirected unexpectedly.
Overview
A URL is made of components, and each component has different encoding rules. A typical address may contain a scheme, hostname, path, query string, and fragment:
https://example.com/products?category=summer&sort=popular#reviews
In this example, /products is the path, category=summer&sort=popular is the query string, and #reviews is a fragment. The ampersand separates query parameters; it is not part of either value. This distinction matters when you encode a URL programmatically.
Percent encoding represents a byte with a percent sign followed by two hexadecimal digits. For example, a space can become %20, an ampersand can become %26, and a question mark can become %3F. The correct representation depends on where the character appears. A question mark that begins a query should remain a question mark, while a question mark inside a parameter value should be encoded so it is treated as data.
As a practical rule, construct the URL from components and encode each value at the point where it enters the URL. Do not encode an already complete URL repeatedly. A URL tool, UTM builder, redirect checker, or application integration should make clear whether it expects a complete URL or individual parameter values.
| Character | Encoded form | Typical reason |
|---|---|---|
| Space | %20 | Separates words inside a value |
& | %26 | Represents an ampersand inside a value |
= | %3D | Represents an equals sign inside a value |
? | %3F | Represents a question mark inside a value |
# | %23 | Prevents a value from being treated as a fragment |
+ | %2B | Preserves a literal plus sign |
% | %25 | Preserves a literal percent sign |
" | %22 | Represents a quotation mark in data |
Unreserved characters such as letters, numbers, hyphens, periods, underscores, and tildes generally do not need percent encoding. Reserved characters may have structural meaning, so encode them when they belong to a value rather than the URL syntax itself.
Checklist by scenario
Building a URL with query parameters
- Start with the base URL and confirm that it is the intended HTTPS or HTTP address.
- Identify each parameter name and value separately.
- Encode the parameter values, not the separators between parameters.
- Join the first parameter with
?and additional parameters with&. - Parse the final result to confirm that every key has the expected value.
Suppose a search endpoint needs the phrase “red shoes & socks”:
https://example.com/search?q=red%20shoes%20%26%20socks
The ampersand inside the search phrase is encoded as %26. If it were left unencoded, a server could interpret “socks” as a separate parameter.
Adding UTM parameters for campaign tracking
Campaign URLs use the same component-based approach. A readable example might be:
https://example.com/offer?utm_source=newsletter&utm_medium=email&utm_campaign=spring_launch
If a campaign value contains spaces or punctuation, encode that value before assembling the URL:
utm_campaign=spring%20launch%20%26%20sale
Keep parameter names consistent with the naming convention used by your analytics setup. For a broader naming workflow, see the UTM Parameters Explained guide. After publishing, test the complete link and verify that the destination and analytics system receive the intended values.
Passing a URL as a parameter
Nested URLs are a frequent source of errors. For example, a login flow might accept a return address:
https://example.com/login?return_to=https%3A%2F%2Fexample.org%2Faccount%3Ftab%3Dorders
The inner URL is encoded as the value of return_to. If the inner question mark and equals sign remain unencoded, the outer application may parse them as part of the login URL's own query string.
Handling non-ASCII text
Encode characters outside the basic ASCII range when placing them in a URL component. A value such as “café” may appear with a percent-encoded representation for the accented character. Use a standards-compliant library rather than manually converting characters, especially for multilingual names, search terms, or user-generated content.
Writing application code
Prefer a URL or query-parameter API provided by your language or framework. Build the base address, set individual parameters, and let the library serialize them. For example, the conceptual workflow is:
url = new URL("https://example.com/search")
url.searchParams.set("q", "red shoes & socks")
request(url)The exact syntax differs by language, but the principle is consistent: encode at the boundary between structured data and a URL string. When accepting a URL from a user or external system, validate the allowed scheme and host according to your application’s requirements before requesting or redirecting to it.
What to double-check
- Separators: Confirm that
?,&, and=are being used as structure only where intended. - Fragments: Anything after an unencoded
#is generally treated as a fragment and may not be sent to the server. Encode a hash when it belongs in a parameter value. - Spaces: Some form-encoding tools represent spaces as
+, while percent encoding represents them as%20. Use the format expected by the receiving endpoint, and do not assume that a literal plus sign means a space in every context. - Double-encoding: If a value already contains
%20, encoding the percent sign again produces%2520. Trace the value through each function to find where encoding is happening twice. - Redirect behavior: Test the original URL and every redirect destination. A redirect layer can decode, normalize, drop, or reorder parameters. Use a redirect checker workflow when the final response differs from the expected one.
- Preview and sharing: Open the link in a browser and inspect how it appears in messaging or social previews. A link preview debugger can help separate URL problems from missing or stale preview metadata.
- Canonical handling: If multiple encoded and unencoded variants resolve to the same page, review canonical and normalization behavior as part of your SEO link workflow.
Common mistakes
Encoding the entire URL too early
Encoding https://example.com/page?a=1&b=2 as one opaque string can turn its structural separators into data. Encode components first, then assemble the address.
Leaving an ampersand inside a value unescaped
This can silently create an extra parameter. It is especially common with search phrases, redirect targets, product names, and manually assembled UTM links.
Using string replacement for security or correctness
Replacing spaces with %20 is not a complete URL-encoding strategy. It does not reliably handle Unicode, percent signs, delimiters, or already encoded input. Use a tested URL library.
Confusing path encoding with query encoding
A slash in a path can separate directories, while a slash inside a query value is usually data. Encoding decisions should be made for the specific component, not copied blindly across the entire URL.
Testing only the browser address bar
Browsers often repair or normalize pasted URLs, which can hide an application bug. Test with the same client, API library, redirect service, or tracking system that will process the link in production.
When to revisit
Keep this checklist nearby whenever you launch campaign URLs, add a QR code or short link, integrate a third-party API, change redirect rules, or accept user-generated URLs. Revisit the implementation before seasonal campaigns and whenever your framework, URL library, analytics workflow, or link-management tool changes.
For a repeatable review, run this sequence:
- Record the intended base URL and parameter values before encoding.
- Generate the URL with a component-aware library or trusted URL tool.
- Parse the result and compare every key-value pair with the original inputs.
- Test special characters, non-ASCII text, nested URLs, and empty values.
- Follow redirects and check the final destination, status, and preserved parameters.
- Save a known-good example with the integration or campaign documentation.
When a link still fails, isolate one variable at a time: remove optional parameters, test a plain value, then add the encoded values back individually. This makes it easier to identify whether the problem is encoding, parsing, redirect handling, analytics configuration, or the destination application.