楓葉工具箱 ToolMaple

URL 編碼解碼

中文與特殊字元 ↔ URL 百分比編碼(percent-encoding)雙向轉換,支援 encodeURI 與 encodeURIComponent。從 server log 看到亂碼 URL 反向 decode 查原意,或把中文網址 encode 後安全傳遞。

  • URL 編碼
  • URL 解碼
  • 中文網址
  • percent encoding
  • url encode decode
  • encodeURI
結果
https://www.toolmaple.com/?q=%E6%A5%93%E8%91%89%E5%B7%A5%E5%85%B7%E7%AE%B1&page=1

為什麼需要 URL 編碼?

URL 規範只允許 ASCII 字元(英數字、特定符號)。 中文、空格、表情符號等需要先「百分比編碼」(如 `%E6%A5%93%E8%91%89`) 才能正確放進 URL。 不編碼會導致 browser、API 解析錯誤。

使用情境

  • 分享含中文查詢參數的網址(Google 搜尋、PTT 文章)
  • 把使用者輸入塞進 query string(要 encode 防止解析錯誤)
  • 從 server log 看到亂碼 URL,反向 decode 查原始查詢

encodeURI vs encodeURIComponent

本工具用 encodeURI,保留 URL 結構字元(: / ? & =)。如果是要把單一參數值嵌入 URL,請改用 encodeURIComponent(會把 `&`、`=` 也編碼)。

相關工具