Quick answer: a URL is made of up to seven parts: scheme, optional credentials, host, optional port, path, query string and fragment. Each answers a different question: how to connect, where to connect, which resource to ask for, and which part of it you want.
One example, taken apart
https://www.example.com:8080/docs/guide.html?lang=en&page=2#install
- Scheme –
https. The protocol used to fetch the resource. Others includehttp,ftp,mailto. - Host –
www.example.com. The server's name. Reading right to left:comis the top-level domain,examplethe registered domain,wwwa subdomain. - Port –
:8080. The network port. It is usually left out because browsers assume 443 for https and 80 for http. - Path –
/docs/guide.html. Identifies the resource on that server. It looks like a folder path, but the server decides what it means. - Query string –
?lang=en&page=2. Starts with?, holdskey=valuepairs separated by&. Used for searches, filters and tracking. - Fragment –
#install. Points to a section within the page. It is handled by the browser and is not sent to the server in the request.
A URL can also carry a username and password before the host (https://user:pass@host/). That form is discouraged because credentials end up in links, history and logs.
What is case sensitive?
The scheme and host are not case sensitive, so EXAMPLE.com and example.com reach the same site. Paths often are: many servers treat /Guide.html and /guide.html as different resources. Query values depend on the application.
Absolute and relative URLs
An absolute URL includes the scheme and host. A relative URL leaves them out and is resolved against the current page: /docs/guide.html starts from the site root, while guide.html starts from the current folder. Relative links keep working if the site's domain changes.
Characters that need encoding
Characters with a special role, such as ? & = # and spaces, must be percent-encoded when they appear inside a part rather than as structure. Searching for fish & chips becomes fish%20%26%20chips. Encode the individual values, not the whole address. The full explanation is in What Is URL Encoding?, and the URL Encoder / Decoder does the conversion.
Practical tips for your own URLs
- Keep paths short, lowercase and readable, with hyphens between words. Search engines treat hyphens as word separators.
- Pick one form of each URL (with or without a trailing slash, with or without
www) and redirect the others to it. - Prefer paths for content that identifies a page and query strings for optional filters.
- Changing a live URL breaks existing links. If you must, add a permanent (301) redirect from the old address.
Planning to print a link? Turn the final, tested address into a QR code.