zaro

What is after in URL?

Published in URL Structure 2 mins read

The part of a URL that comes after the question mark ? is called the query string or simply the query.

This query string is used to pass data to the server. It consists of one or more parameter-value pairs. Each pair is separated by an ampersand &. The parameter and its value are separated by an equals sign =.

Here's a breakdown:

  • URL Structure: [protocol]://[domain]/[path]?[query]

  • Protocol: http:// or https:// (e.g., https://)

  • Domain: The website address (e.g., www.example.com)

  • Path: The specific location on the website (e.g., /search)

  • Query: The data sent to the server after the ?

Example

Consider the following URL:

https://www.example.com/search?q=example+search&page=2

In this example:

  • /search is the path.
  • ?q=example+search&page=2 is the query string.
  • q is a parameter with the value example+search.
  • page is a parameter with the value 2.
  • & separates the two parameter-value pairs.

The server uses this information to process the request. For example, in this case, it might search for "example search" and display the results from page 2.

Important Considerations

  • If a URL also contains a #, the query string appears before it. The part after the # is called the fragment identifier and is not sent to the server. For instance, in the URL https://www.example.com/page?param1=value1#section2, ?param1=value1 is the query string, and #section2 is the fragment identifier (also known as the URL hash).

  • Changing the query string generally results in a new HTTP GET request to the server, fetching a different resource or a modified version of the same resource.

  • Spaces in the values are usually encoded as + or %20.