點擊上方的語言選單以切換語言
RFC 3986 是由 IETF(Internet Engineering Task Force)制定的標準,正式名稱為 Uniform Resource Identifier (URI): Generic Syntax。
本文件定義了 URL / URI 的通用語法結構與字元編碼方式(Percent-Encoding)。
scheme://authority/path?query#fragment
範例:
https://example.com/products/list?id=100#top
| 部分 | 說明 |
|---|---|
| scheme | 協定(http, https, ftp...) |
| authority | 網域名稱或 IP |
| path | 資源路徑 |
| query | 查詢參數 |
| fragment | 頁面錨點 |
A–Z a–z 0–9 - _ . ~
這些字元可以直接使用,不需要進行編碼。
: / ? # [ ] @ ! $ & ' ( ) * + , ; =
這些字元在 URL 中有特殊用途,若作為資料使用,必須進行編碼。
編碼格式:
%HH
HH 為字元的十六進位表示(ASCII 或 UTF-8 byte)。
| 字元 | ASCII | 編碼 |
|---|---|---|
| 空白 | 0x20 | %20 |
| ? | 0x3F | %3F |
| # | 0x23 | %23 |
所有非 ASCII 字元必須:
例如:「中文」
UTF-8: E4 B8 AD E6 96 87 Percent-Encoding: %E4%B8%AD%E6%96%87
eristeinfleißigerSchülerwährenddueinegroßeLehrerinbistalsokönntihrFreundesein
此字串包含:
這些都不是 ASCII 字元,因此必須進行 UTF-8 + Percent-Encoding。
eristeinflei%C3%9FigerSch%C3%BClerw%C3%A4hrenddueinegro%C3%9FeLehrerinbistalsok%C3%B6nntihrFreundesein
編碼後才符合 RFC 3986 規範。
| 情境 | 表示方式 |
|---|---|
| RFC 3986 標準 URI | %20 |
| application/x-www-form-urlencoded(HTML 表單) | + |
若未遵守 RFC 3986,可能導致:
本文件依 RFC 3986 標準整理說明