Introduction to URLs
A URL, or Uniform Resource Locator, is the complete address used to locate a resource on the internet. A resource can be a webpage, image, video, file, or API endpoint.
When you type a URL into a browser, you are giving precise instructions on how and where to retrieve data.
What Does a URL Represent?
A URL answers three important questions:
- How should the request be made?
- Where is the resource located?
- What specific resource is being requested?
Each part of the URL contributes to answering these questions.
Basic Structure of a URL
scheme://hostname:port/path?query#fragment
Not every URL contains all components, but this structure represents the full form.
Scheme (Protocol)
The scheme defines the protocol used to communicate with the server. It tells the browser how to handle the request.
Common schemes include:
- http – Standard web communication
- https – Secure web communication
- ftp – File transfer
https://
HTTPS is now the standard for modern websites because it encrypts data in transit.
Hostname (Domain Name)
The hostname identifies the server where the resource is hosted. It is usually a domain name that DNS resolves into an IP address.
www.example.com
The hostname may include subdomains and uniquely identifies a location on the internet.
Port Number (Optional)
The port specifies the exact service running on the server. If omitted, the browser uses default ports.
https://example.com:443
Common default ports:
- 80 – HTTP
- 443 – HTTPS
Path
The path identifies the specific resource or location within the server. It often represents directories or routes.
/products/electronics
In modern applications, paths are frequently mapped to backend routes rather than physical files.
Query Parameters
Query parameters send additional data to the server. They begin with a question mark and are written as key-value pairs.
?category=phones&sort=price
Query parameters are commonly used for:
- Filtering results
- Searching data
- Pagination
- Tracking analytics
Fragment Identifier
The fragment identifies a specific section within a resource. It is handled entirely by the browser and is not sent to the server.
#reviews
Fragments are often used for:
- Page anchors
- Single-page applications
Complete URL Example
https://www.example.com:443/products?category=laptops#specs
| Component | Value |
|---|---|
| Scheme | https |
| Hostname | www.example.com |
| Port | 443 |
| Path | /products |
| Query | category=laptops |
| Fragment | #specs |
URL Encoding
Some characters are not allowed directly in URLs. URL encoding replaces them with safe characters.
Space → %20
This ensures URLs remain valid and interpretable.
SEO-Friendly URL Structure
Clean URLs improve both user experience and search engine visibility.
Good URL practices include:
- Using readable words
- Avoiding unnecessary parameters
- Keeping URLs short and meaningful
Good: /blog/url-structure-guide Bad: /index.php?id=12345
Real-World Example: API URL
APIs rely heavily on structured URLs to represent resources and actions.
https://api.example.com/users/123/orders
Each part of the path clearly represents a resource relationship.
Why Understanding URL Structure Matters
Understanding URL components helps with:
- Web development and routing
- API design
- SEO optimization
- Security awareness
- Debugging network issues
URLs are the entry point to every web interaction. Mastering them makes the web far easier to understand and build.