Absolute URL: It is a URL that contains all the information that is important for locating the resources. The thing which is included in the absolute URL is the protocol (HTTPS) in the site’s domain at the starting point of the URL.
Relative URL: It is a short URL that holds the name of the domain and exact things which is only allowed to access on the same server or page.
/* Absolute Url */ https://www.geeksforgeeks.org/ /* Relative Url */ geeksforgeeks.org
Approach: Absolute URL has protocol (HTTPS) included in the starting. We can simply check if the URL has https:// in front or not. If it is found we return true else false.
For checking protocol, we use regex (regular expression).
- ^: It is used for selecting from starting.
- https: It is used for selecting the text.
- \: It is used for a special regex character matches the front character.
Example: Below example explains the use of above approach.
For non-absolute URL’s:
For absolute URL’s: