URL Kodér/Dekodér Časté dotazy

Kódování a dekódování URL řetězců

What's the difference between encodeURI and encodeURIComponent?

encodeURI encodes a complete URL while preserving structural characters like :, /, ?, and &. encodeURIComponent encodes everything except unreserved characters (letters, numbers, - _ . ~), making it suitable for query parameter values. Use encodeURI for complete URLs, encodeURIComponent for individual components like search terms or form values.

Why is space encoded as %20 or +?

Both are valid representations of space in different contexts. %20 is the standard percent-encoding used in URL paths and most URL components. The + character represents space specifically in application/x-www-form-urlencoded format, which is used for HTML form submissions and query strings. Modern APIs typically use %20, but + is still common in query strings.

Do I need to encode file paths in URLs?

Yes, if file paths contain spaces or special characters, they must be URL encoded. Spaces become %20, and characters like ? or # (which have special URL meaning) must be encoded to prevent misinterpretation. Modern browsers often display decoded URLs for readability, but the underlying request uses encoded forms.

Is URL encoding secure?

URL encoding is not a security measure—it's purely functional encoding for character safety. Anyone can decode %20 to a space instantly. However, proper URL encoding is essential for security: it prevents injection attacks by ensuring user input doesn't break out of query parameter contexts. Always encode user input when building URLs.

Why do non-ASCII characters have multiple percent codes?

Non-ASCII characters are first encoded as UTF-8 bytes, then each byte is percent-encoded separately. For example, the German ö is two bytes in UTF-8 (C3 B6), so it becomes %C3%B6. Chinese, emoji, and other Unicode characters may require even more bytes. This ensures proper handling of international characters in URLs.

Vyzkoušet nástroj

Kódování a dekódování URL řetězců

URL Kodér/Dekodér