了解URL結構 🔗
您每天使用網際網路時都會看到URL,但可能不太了解每個部分的含義。理解URL的結構會讓Web開發變得容易得多!讓我們一步步來了解。
用日常生活比喻URL?
讓我們把URL比作郵政地址。
郵政地址的故事 📬
台灣 台北市 信義區 信義路123號 ABC大樓 5樓 501室
↓ ↓ ↓ ↓ ↓ ↓ ↓
國家 城市 區 街道 建築物 樓層 房間號
URL也類似:
https://www.example.com:443/products/shoes?color=red&size=10#reviews
↓ ↓ ↓ ↓ ↓ ↓
協定 域名 埠號 路徑 查詢字串 雜湊
URL的定義
URL (Uniform Resource Locator)
- 表示網際網路上資源(頁面、圖像、檔案等)位置的地址
- 也稱為"Web地址"或"連結"
一眼看懂URL完整結構
https://user:pass@www.example.com:443/products/shoes?color=red&size=10#reviews
└──┬─┘ └────┬────┘└───────┬───────┘└┬┘└──────┬──────┘└────────┬────────┘└──┬──┘
協定 認證資訊 域名 埠號 路徑 查詢字串 雜湊/片段
讓我們逐一詳細了解!
1. 協定 (Protocol) 🔐
連接網站的方法
https://example.com
└──┬─┘
協定
主要協定
HTTP (HyperText Transfer Protocol)
http://example.com
- 普通網站連接方法
- 無安全性 ⚠️
- 資料未加密
- 現在幾乎不使用
HTTPS (HTTP Secure)
https://example.com
- 安全的網站連接方法 🔒
- 資料已加密
- 現代網站標準
- 顯示鎖圖示 🔒
其他協定
ftp://example.com # 檔案傳輸
mailto:user@email.com # 發送電子郵件
file:///C:/folder # 本機檔案
提示
始終使用HTTPS! 特別是在登入、支付、輸入個人資訊時,一定要確認是HTTPS。
2. 域名 (Domain) 🌐
網站的名稱
https://www.example.com
└──────┬──────┘
域名
域名結構
www.example.com
└┬┘ └──┬──┘└┬┘
子域 名稱 TLD
名 (頂級域名)
頂級域名 (TLD - Top Level Domain)
.com → 商業(最常見)
.net → 網路
.org → 組織/非營利
.edu → 教育機構
.gov → 政府
.io → IT/新創公司(流行)
.tw → 台灣
子域名 (Subdomain)
www.example.com → 網站
blog.example.com → 部落格
api.example.com → API伺服器
admin.example.com → 管理頁面
實際示例
https://blog.example.tw
└┬┘ └──┬──┘└┬┘
子域 主域名 TLD
名
3. 埠號 (Port) 🚪
從伺服器的哪個門進入
https://example.com:443
└┬┘
埠號
預設埠號
通常省略(自動添加):
http://example.com → http://example.com:80 (自動)
https://example.com → https://example.com:443 (自動)
常見埠號
| 埠號 | 用途 |
|---|---|
| 80 | HTTP (Web) |
| 443 | HTTPS (安全Web) |
| 21 | FTP (檔案傳輸) |
| 22 | SSH (遠端連接) |
| 3000 | 開發伺服器 (Node.js) |
| 3306 | MySQL資料庫 |
| 5432 | PostgreSQL |
| 8080 | 備用HTTP |
開發中?
http://localhost:3000 # React開發伺服器
http://localhost:8080 # Spring Boot
http://127.0.0.1:5000 # Flask/Python