What is a URL?
A URL (Uniform Resource Locator) is a complete web address that specifies the exact location of a resource on the internet. URLs provide a standardized way to identify and access web pages, files, images, APIs, and other resources. Every link you click or address you type in a browser is a URL.
URL Structure
https://www.example.com:443/path/page.html?query=value#section
│ │ │ │ │ │ │
│ │ │ │ │ │ └── Fragment
│ │ │ │ │ └── Query string
│ │ │ │ └── Path
│ │ │ └── Port (optional)
│ │ └── Domain name
│ └── Subdomain
└── Protocol/Scheme
URL Components
| Component | Example | Purpose |
|---|---|---|
| Protocol | https:// | How to access (HTTP, HTTPS, FTP) |
| Subdomain | www. | Optional prefix |
| Domain | example.com | Server address |
| Port | :443 | Network port (usually implied) |
| Path | /page.html | Resource location |
| Query | ?id=123 | Parameters |
| Fragment | #section | Page section anchor |
URL vs Domain vs URI
| Term | Definition | Example |
|---|---|---|
| Domain | Just the domain name | example.com |
| URL | Full address with protocol | https://example.com/page |
| URI | Any identifier (superset of URL) | mailto:user@example.com |
URL Encoding
Special characters require encoding:
Space → %20
& → %26
= → %3D
/ → %2F
? → %3F
Example:
"hello world" → "hello%20world"
URL Best Practices
For SEO
1. Use descriptive paths: /products/blue-shoes
2. Keep URLs short and readable
3. Use hyphens, not underscores
4. Lowercase letters preferred
5. Avoid parameters when possible
For Security
1. Always use HTTPS
2. Validate URL inputs
3. Avoid exposing sensitive data in URLs
4. Use canonical URLs
Common URL Protocols
| Protocol | Purpose | Default Port |
|---|---|---|
| http:// | Unencrypted web | 80 |
| https:// | Encrypted web | 443 |
| ftp:// | File transfer | 21 |
| mailto: | Email links | N/A |
| tel: | Phone links | N/A |
URLs are the addressing system of the web, providing a universal way to locate and access resources across the internet.