A pathname is a combination of characters and symbols describing the location of a resource on a computer.
A pathname identifies the hierarchy of directories, also known as the path, that leads to the location of a file on a computer.
If you are on a computer running Microsoft Windows, find a document stored in your “Documents” folder, right-click to view the context menu, and select “Properties”. In the properties menu that appears you will find a line titled “Location” followed by something that looks like this:
That sequence of words and symbols is the pathname that explains how to get to the location where the document you selected is stored. What that pathname expresses is that document selected is housed in the “Documents” folder, which resides in the “Public” folder, which can be found in the “Users” folder, which is located on the hard drive named “C:”.
Pathnames are also used on the web. Consider the following URL:
In this example, everything following “.com” is the path portion of the URL. The webpage being viewed is composed of a file titled “index.html”, which can be found within the “categories” directory, which is contained within the “products” directory, which in turn can be found inside the “shop” directory, which exists at the domain “example.com” and can be accessed over the “HTTP” protocol.
Not everything in a URL that comes after the domain is part of a pathname. There are two other symbols used to denote other types of content in a URL:
Queries (?) and fragments (#) can be appended to a URL and give the browser or the server additional instructions about how to process the web page. Queries and fragments are instructions and are not part of the pathname.
Frequently Asked Questions
What’s the difference between an absolute path and a relative path?
A relative path indicates the path to a resource using the current directory as a starting point. An absolute path does not use the current directory as a starting point. It’s easiest to understand the difference by using relative and absolute URLs as an example. Imagine for a moment that you were looking at webpage located here:
From this page, if we wanted to link to a different page, such as the glossary homepage we could do that using either a relative or an absolute URL:
Relative URL: ../glossary/
Absolute URL: http://learnthenet.com/glossary/
If we use the relative URL, when you click on the link your browser will ask the server to go back up one level in the directory hierarchy (that’s what the “..” is about), look for the “glossary” directory, and load the result.
If we use the absolute URL, when you click on the link your browser will instead begin by looking for “http://learnthenet.com” and then ask the server to open the “glossary” directory and load the result page.
The end result in both cases is the same, you land at the glossary homepage for Learn the Net. The difference is in what request your browser sends to the server.