URL 编解码

安全编码/解码 URL 组件

Input

Loading editor...

Output

Loading editor...

Encode URL components without breaking your queries

Special characters — spaces, ampersands, slashes, non-ASCII letters — break query strings if they're not percent-encoded. The right tool for the job depends on whether you're encoding a full URL or a single component, and choosing wrong is a frequent source of bugs. This tool handles both cases and shows you exactly what each character becomes.

Use the tool when you need to

Encode a query parameter value

Percent-encode a search term, slug, or special string before slotting it into a query string.

Decode a URL from a log

Reverse %20, %2F, and other escapes to read what the request actually contained.

Audit an OAuth or callback URL

Check that the redirect, scope, and state parameters are encoded correctly before debugging the flow.

How to encode or decode URL components

  1. 1

    Paste the URL or component into the input area.

  2. 2

    Click Encode or Decode based on which direction you need.

  3. 3

    Copy the result and slot it back into your URL or test request.

Common URL-encoding workflows

Build a search redirect

Encode the user's query before constructing the destination URL to avoid breaking on spaces or symbols.

Read a redirect from logs

Decode a logged URL to confirm what the user clicked and which parameters arrived.

Verify an OAuth state parameter

Decode the state to confirm it round-trips through the auth provider untouched.

相关工具

常见问题

URL 编码(percent-encoding)会把不安全字符替换为 % 加两位十六进制数。例如空格会变成 %20,& 会变成 %26,用来避免特殊字符破坏 URL 解析。

在 URL 中有特殊含义的字符通常需要编码:空格、&、=、?、#、/、@ 以及非 ASCII 字符。字母、数字和 - _ . ~ 属于安全字符,一般不需要编码。

只粘贴参数值(不要粘贴整个 URL),然后点击 Encode。比如搜索词是 'hello world & more',编码后会得到 'hello%20world%20%26%20more',可以安全放进 query string。

encodeURI 用于编码完整 URL,会保留 URL 结构字符(如 :、/、?、#、&)。encodeURIComponent 会编码除字母、数字和 - _ . ~ 之外的几乎所有字符,更适合用于单个参数值。