Bỏ qua đến nội dung chính
FreeOnlineTools Go
Tiếng Việt
how-to

Cách Mã hóa và Giải mã URL: Hướng dẫn Đầy đủ

By FreeOnlineTools Team · Updated 2026-08-28

Quick Answer

URL encoding chuyển ký tự unsafe thành chuỗi %XX trong đó XX là giá trị hex của byte. Khoảng trắng thành %20 (hoặc + trong form data), ký tự Trung Quốc thành chuỗi %XX multi-byte. Dùng URL Encoder và URL Decoder miễn phí —tất cả xử lý cục bộ.

Introduction

URL encoding, còn gọi percent-encoding, là cơ chế mã hóa ký tự reserved và unsafe trong URL để URL có thể truyền an toàn qua internet. URL chỉ chứa tập ký tự ASCII giới hạn; bất kỳ ký tự nào khác (khoảng trắng, chữ phi-ASCII, ký hiệu) phải được percent-encoded as chuỗi bắt đầu bằng % theo sau hai chữ số hex đại diện giá trị byte.

Step by Step

  1. Identify what needs encoding

    Characters that are not in the unreserved set (A-Z, a-z, 0-9, -, ., _, ~) must be percent-encoded. This includes spaces, query separators like = and &, slashes, and all non-ASCII characters such as Chinese, Arabic, or emoji.

  2. Encode the URL or query string

    Paste your text into the URL Encoder tool. It uses encodeURIComponent() to encode every reserved character. The result appears instantly in the output field.

  3. Copy the encoded result

    Click the Copy button to copy the percent-encoded string. You can now safely embed it in a URL query parameter, API request, or form submission.

  4. Decode an encoded URL

    Paste an encoded URL or query string into the URL Decoder tool. It uses decodeURIComponent() to restore the original characters. Verify the decoded output matches your expectation.

  5. Verify edge cases

    Check that spaces are decoded correctly (%20 vs +), that multi-byte UTF-8 sequences decode to the right character, and that already-encoded strings are not double-encoded.

Examples

Encode text with a space

Input: Hello World

Output: Hello%20World

Encode a path separator

Input: a/b

Output: a%2Fb

Encode Chinese characters (UTF-8)

Input: 你好

Output: %E4%BD%A0%E5%A5%BD

Decode an encoded query parameter

Input: key%3Dvalue%26foo%3Dbar

Output: key=value&foo=bar

Common Problems

  • Double-encoding: encoding an already-encoded string turns %20 into %2520. Always check whether input is already encoded before re-encoding.
  • Confusing encodeURI with encodeURIComponent: encodeURI keeps reserved characters like /, ?, & intact for full URLs, while encodeURIComponent encodes everything for query parameter values.
  • Space handling: %20 is the percent-encoded form; + is only valid in application/x-www-form-urlencoded body data, not in URL path or query string per RFC 3986.
  • Non-UTF-8 legacy encodings: modern browsers encode as UTF-8, but legacy systems may use GBK or Latin-1, causing mojibake when decoded on the other side.

Tips

  • Use encodeURIComponent() for individual query parameter values, and encodeURI() for entire URLs that are already well-formed.
  • When building query strings, encode the value but not the = or & separators —encode each value separately then join with &.
  • Use our URL Encoder and Decoder tools to debug API calls that return 400 errors due to malformed query strings.
  • Always decode on the server side using the same character encoding (UTF-8) to avoid mojibake.

Related Tools

Related Guides

References