Comment encoder les URLs : quest-ce que encodage URL
Apprenez ce quest lencodage URL et comment encoder/decoder.
What is URL encoding and why it exists
URL encoding (percent-encoding) converts special characters to %XX sequences. URLs can only contain a limited ASCII subset.
Example: Space → %20. "ñ" → %C3%B1. name=John Doe&city=São Paulo → name=John%20Doe&city=S%C3%A3o%20Paulo.
Why: URLs have characters with special meaning: ? & = / #. If your data contains these, they must be encoded.
Encode/decode URLs with the NexTools URL encoder.
Characters that need encoding and which don't
Safe (no encoding): A-Z a-z 0-9 - _ . ~
Reserved:
| Char | Encoded | URL meaning |
|---|---|---|
| space | %20 or + | Word separator |
| ? | %3F | Query string start |
| & | %26 | Parameter separator |
| = | %3D | Key=value |
| / | %2F | Path separator |
| # | %23 | Fragment |
Non-ASCII: Converted to UTF-8 bytes, each encoded. "ñ" → C3 B1 → %C3%B1.
URL encoding in JavaScript, Python, and terminal
JavaScript:
encodeURIComponent("John Doe")→"John%20Doe"— encodes EVERYTHING exceptA-Za-z0-9 - _ . ~encodeURI("https://example.com/search?q=hello world")— preserves URL structure
Critical difference: encodeURIComponent for parameter VALUES. encodeURI for full URLs.
Python: from urllib.parse import quote; quote("John Doe")
For Base64 encoding (different from URL encoding), use the NexTools Base64 encoder.
Common URL encoding mistakes
1. Double encoding. %20 becomes %2520. Server sees literal "%20" instead of space.
2. Confusing encodeURI and encodeURIComponent. encodeURIComponent on a full URL breaks it.
3. Space as + vs %20. In form query strings: +. In rest of URL: %20.
4. Not encoding Unicode. URLs with "ñ", "ü", CJK must be encoded.
URL encoding in REST APIs and HTML forms
API query params: Always encode values. GET /api/search?q=C%2B%2B. Without encoding, "C++" becomes "C ".
HTML forms: Browser auto-encodes with application/x-www-form-urlencoded.
JSON APIs: Body data as JSON doesn't need URL encoding. Only query params and endpoint URL need it.
Validate JSON before sending with the NexTools JSON validator.
IDN and internationalized URLs
IDN: Domains with non-ASCII like münchen.de → Punycode: xn--mnchen-3ya.de.
IRI: Extension allowing Unicode directly. Browsers show readable version, send encoded.
For friendly URLs, use the NexTools slug generator.
How to use the NexTools URL encoder
The NexTools URL encoder:
Encode: Paste text → get %XX encoded version.
Decode: Paste encoded URL → get readable version.
All in browser. Useful for debugging broken URLs, preparing API parameters, understanding encoded URLs in server logs.
URL encoding vs Base64 vs HTML entities: don't confuse them
URL encoding (%XX): For characters in URLs.
Base64: For encoding binary data as text. Different purpose. See our Base64 guide.
HTML entities: For special characters in HTML. < → <.
Rule: Data in URL → URL encode. Binary in request body → Base64. In HTML page → HTML entities.
Essayez cet outil :
Ouvrir l'outil→Questions fréquentes
What's the difference between encodeURI and encodeURIComponent
encodeURI encodes a FULL URL preserving structure (doesn't encode : / ? # &). encodeURIComponent encodes a URL COMPONENT (encodes everything except A-Za-z0-9 - _ . ~). Use encodeURIComponent for parameter values, encodeURI for full URLs.
Why are spaces encoded as %20 sometimes and + other times
In HTML form query strings (application/x-www-form-urlencoded): +. In the rest of the URL (path, fragment): %20. Two historical conventions that coexist.
What is double encoding and how to avoid it
Encoding an already-encoded URL. %20 becomes %2520. To avoid: decode first with decodeURIComponent, then encode.
Do browsers encode URLs automatically
Partially. Browsers encode non-ASCII in the address bar but show readable version. In forms, auto-encoded. In JavaScript (fetch), you must manually encode parameters.
Are URL encoding and Base64 the same
No. URL encoding (%XX) is for URL special characters. Base64 converts binary to ASCII text. Different purposes, not interchangeable.
How do I encode Chinese or Japanese characters in a URL
Convert to UTF-8 bytes, encode each as %XX. Chinese '中' (UTF-8: E4 B8 AD) → %E4%B8%AD. Tools like NexTools handle this automatically.