統一資源定位器(Uniform Resource Locator,URL)是網際網路資源的唯一地址標識。深入理解其語法結構與各類協議方案,能幫助開發者精準構建超連結、配置伺服器資源路徑,並解決跨域引用問題。
標準 URL 遵循以下語法:
scheme://host.domain:port/path/filename
| 元件 | 說明 | 預設值/備註 |
|---|---|---|
| scheme | 定義網際網路服務類型 | 最常見為 http、https |
| host | 域內主機名稱 | 省略時 HTTP 預設為 www |
| domain | 網域名稱(如 example.com) | 必填 |
| :port | 伺服器連接埠號 | HTTP 預設 80,HTTPS 預設 443,常省略 |
| path | 伺服器上資源的路徑 | 省略時指向網站根目錄 |
| filename | 具體文件名稱 | 預設通常為 index.html、default.asp 等 |
例如 https://www.example.com/html/tutorial.html 中:
httpwwwexample.com/html/tutorial.html| Scheme | 用途 | 範例 |
|---|---|---|
http | Web 頁面存取 | https://www.example.com |
https | 加密 Web 存取 | https://secure.example.com |
ftp | 檔案傳輸協議 | ftp://files.example.com/pub/file.zip |
mailto | 電子郵件連結 | mailto:user@example.com |
news | Usenet 新聞群組 | news:comp.lang.html |
telnet | 遠端終端機連線 | telnet://host.example.com |
file | 本機檔案系統 | file:///C:/Users/Docs/readme.txt |
<a href="news:comp.lang.html">HTML Newsgroup</a>
<a href="ftp://ftp.example.com/pub/winzip.exe">Download WinZip</a>
<a href="mailto:support@example.com?subject=Feedback">聯繫我們</a>
掌握 URL 完整語法與各類 Scheme 特性,能讓你在開發超連結、API 端點、資源引用時更精準、更具跨平台相容性。