URL 编码解码:空格、中文与特殊字符如何安全地放进链接

URL Encoding Explained: Spaces, Chinese Characters, and Special Chars in Links

为什么链接里要转义

URL 本身只允许一部分字符直接出现。空格、中文、引号、尖括号、# 等字符如果原样放进链接,要么在请求时被截断,要么被服务器误解。编码就是把这些字符替换成安全形式,解码则是还原。

这个工具能做什么

打开 URL 编解码工具,粘贴文本即可编码或解码。工具区分两种粒度,对应 JavaScript 里两个不同函数:

  • 组件编码(encodeURIComponent):连 / : ? & 等分隔符也一起转义,适合放在查询参数里。
  • 整体编码(encodeURI):保留分隔符不动,只转义其他特殊字符,适合编码整个地址。

中文如何处理

中文等 Unicode 字符会先被转换为 UTF-8 字节流,再逐个字节编码成 %XX 形式。例如"工具"会被编码成 %E5%B7%A5%E5%85%B7。因此只要服务端和客户端都用 UTF-8,中文就能安全地放在链接里。

常见误区

  • 解码不等于解密:任何人去掉百分号编码都能还原原文。
  • 别整体编码查询参数:会把 & = 也转义掉,服务端就分不清参数了。
  • 空格可以是 +:在表单与查询串里空格常编码为 +,而路径里是 %20。

Why links must be escaped

A URL only allows a limited set of characters directly. Spaces, Chinese text, quotes, angle brackets, and # either truncate the request or get misinterpreted by the server. Encoding replaces those characters with their safe form; decoding restores them.

What this tool does

Open the URL encoder and paste text to encode or decode it. Two granularities are available, matching the two JavaScript functions:

  • Component encoding (encodeURIComponent) — also escapes separators like / : ? &; use this inside a query parameter.
  • Whole-URL encoding (encodeURI) — keeps separators intact and escapes everything else; use it on a complete address.

How Chinese text is handled

Unicode characters are converted to their UTF-8 byte stream, then each byte is written as a %XX escape. For example, the two characters for "tool" become %E5%B7%A5%E5%85%B7. As long as both ends speak UTF-8, Chinese travels safely in links.

Common mistakes

  • Decoding is not decrypting — anyone can strip the percent escapes to recover the original.
  • Don't whole-encode query parameters — it masks & and =, and the server can no longer split them.
  • A space may be + — in forms and query strings a space encodes as +, while in paths it is %20.
Open the tool打开工具