Understanding URLs

To be able to create links, you need to understand URLs. A URL stands for uniform resource locator (URL) and it has several parts:

  • Protocol
  • Domain name
  • Directory (folder)
  • Filename and file extension

The following example shows these parts in a URL:

Parts of a URL
Parts of a URL

The first part, as the graphic shows above, of a URL is the name of the protocol: http. The http protocol is a set of rules that enables web browsing. Specifically, we want to use the http protocol to access http://www.scriptingmaster.com/html/creating-links.asp.

The second part of the URL is the domain name. The domain name simply is a text name that corresponds to the IP address of the server that serves that web site. Because a text name is easier to remember and recognize, a domain name is used rather than an IP address. (The IP address that corresponds to scriptingmaster.com is 64.40.96.247 thus we could have used http://64.40.96.247/html/creating-links.asp. However, again a domain name is much easier to remember and recognize than using IP address.) You may have seen domains that end with .edu (for education), .org (for organization), .info (for information), .mobi (for mobile), etc. When creating links, use a valid domain name (including .com, edu, or .info) and avoid use of IP addresses.

The third part of the URL specifies the directory or the folder name. The directory simply is the actual location of the file we want to access/link: creating-links.asp. To avoid broken links, ensure the directory exists and contains the file that you want to link to.

The last part of the URL is the file name: creating-links.asp. When creating links, make sure the file exists and that you use the appropriate file extension (such as .htm, .html, .asp, or .php).

It is a good practice to first access the URL before using it as a link. Doing that will ensure:

  1. you are linking to a valid URL. If you don't access the page, how would you know if it exists?
  2. indeed it is the page you intend to link to