Web Basics — URLs - odigity/academy GitHub Wiki

It is important to understand the different parts of a URL. Let's use http://www.example.com:80/help/search.html?query=monkey&results=10 as our example.

http://  www.example.com  :80  /help/search.html  ?query=monkey&results=10
-------  ---------------  ---  -----------------  ------------------------
protocol     domain       port       path               querystring
  • Protocol — Which protocol to use to fetch the resource. This is usually http or https, but if you drag a file from your computer onto your browser window, the resulting URL will use the file:// protocol. Most browsers will default to 'http' if you don't specify.

  • Domain — The domain name is used to find the web server's location on the internet. Specifically, the browser (or operating system) will send a request to a domain name server to get the IP address for that domain, then attempt to connect to the web server at that address.

  • Port — When connecting to another computer on the internet, you have to specify which port on that computer you want to connect to. (Most computers have 65,536 possible port numbers, from 0 to 65,535.) The default port is 80 for HTTP and 443 for HTTPS. If a URL doesn't specify the port, the default is assumed.

  • Path — This specifies the location of the web resource on the web server. The default is / if you don't specify, so if you enter www.google.com in your browser, it will contact the web server at www.google.com and request the / path (aka "root path"). If the path ends with a /, the web server will usually look for a file in that directory called index.html and return that. (If no index exists, some web servers will instead return a directory listing for that director.)

  • Querystring — This optional part lets you provide arbitrary parameters (name/value pairs) to the web server in order to perform a task or customize the resource being fetched. Querystring parameters are often used to submit the results of a form, such as when searching google for monkeys: https://www.google.com/?q=monkeys

Fragments

You will sometimes see URLs with a section at the end that looks like #something. Example: https://github.com/odigity/academy/wiki/Web-Basics-—-URLs#fragments

This is called a fragment, and is not actually passed to the web server. Instead, after the page is loaded, the browser will look for the fragment identifier (usually in the form of an id HTML attribute) in the page and scroll the page down to that point.