Providing Solutions For Web Development Languages and Platforms

Absolute Path VS Relative Path

Absolute Path VS Relative Path

What is Path?


A Path is a Unique Location of a file or a folder in File System of an OS (Operating System). Path to that file/folder is a combination of delimiter forward slash (/) or backward slash (\) and alpha-numeric characters.

Web is known to be a Collection of Hyperlinks (Commonly known as Links). Only Web Pages has the ability to create and follow link that makes it unique from Communication Media.

Link creation in HTML is very easy. You can link a text to any other file or any media like Image, Video or anything else. All you need to do is to have a file path or Web Page path ready to link.

As you all know, HTML needs an Anchor Tag (<a>) to hyperlink any text to a link or media. HTML anchor tag requires path for the link in href attribute. This will create the link by just following these 2 steps.

Part of Confusion in this scenario occurs only when after adding anchor tag (<a>) as Step 1, you need to add link in href attribute as Step 2. Still Today, It is a matter of great confusion that to provide Full Path or Short Path there.

Full Path refers to Absolute Path and Short Path refers to Relative Path.

Connecting Web Pages plays a crucial role in Performance of Website and it’s SEO. Don’t get confused while making connections between Web Pages or Web Pages to Files. A quick read will get you out of the confusion that Which Path format to use and when?

Here, you will come to know difference between Absolute Path and Relative Path. Also get to know how links work? Let’s get started with Absolute Path vs Relative Path.

What is Absolute Path?


Absolute Path is defined as having Complete address for location of a file or Page starting from root directory. See the Absolute Path of the page you are reading either in your Browser’s URL Box or down below :

https://www.developerspost.com/html-solutions/absolute-path-vs-relative-path/

Absolute path above includes location of the page from the root i.e. Domain in this case. Starting from Protocol https:// including Domain name www.developerspost.com and category URL html-solutions ending with current page URL absolute-path-vs-relative-path makes the full path or absolute path for the current page.

Absolute paths can easily be copied and directly pasted in Browser’s URL Box to go to specific link with just a Go. It must always include Protocol when applying in anchor tag to make it work for all users.

What is Relative Path?


Relative Path is defined as having Short address for location of a file or Page relating to current file/directory. See the Relative Path of the page you are reading down below :

/absolute-path-vs-relative-path

Curious to know Why Relative path for current page only includes Current URL?

As Path tells you about the location of a file. Relative Path includes path in relation to the current directory considering Current Directory as the root.

Relative Paths can be inserted in anchor tags only when anchor including page is in the same directory linked page or file is in.

Now, Question arises – How does your browser know Where to go when user clicks on link having Relative Path?

Simple, Browser looks for the location of file relative to the page where the link is embedded and loads the complete URL prepending Protocol and Directories itself up to Current Directory.

So, Is the Relative Path only limited to current directory? For previous directory file, one have to again provide Absolute Path?

No No No… Why to use absolute path for that, when you have two periods and a forward slash (../) to jump back from current directory. Let’s Simplify it with the help of an Example :

Current Page Absolute Path – https://www.developerspost.com/html-solutions/absolute-path-vs-relative-path/
Current Page Relative Path – /absolute-path-vs-relative-path

Now, if you want to go relatively to Category Page html-solutions. Just follow this –
../html-solutions, you will be redirected to previous link i.e Category Page HTML Solutions

You can use any of the Path Format. Developers Post Suggests to use Absolute Paths only when you need to provide other Website URL. Use Relative Paths for links of your own website.

Get Absolute vs Relative Positioning more clear by referring to differences below :

Absolute Path VS Relative Path


Absolute Path differs from Relative Path in many forms. Absolute Path vs Relative Path is a point of discussion because they differs in Web Syntax discussed above and also having differences in Windows and linux.

Absolute Path Vs Relative Path in Windows

Windows Absolute Path

C://xampp/htdocs/ProjectFolder/index.php

Windows Relative Path

index.php

While using Relative Path, you must be in the directory where the file exists. But, In case of Absolute Path, You can be anywhere and still can access the file index.php. System will find it for you.

How to find Absolute Path in Windows

Finding Absolute Path for a file is quite easy. Just follow the following steps and you are done :

  • Select the file for which you want to get the path
  • Right Click on it
  • Click Properties
  • Find the text “Location” which indicates the Absolute Path for the file

Find Absolute Path for File in Windows

Absolute Path Vs Relative Path in Linux

Linux Absolute Path

/home/users/c/developerspost/public_html/cgi-bin

Linux Relative Path

/public_html/cgi-bin

How to find Absolute Path in Linux

Finding Absolute Path for a file in Linux is quite easy. Just use the pwd command and you got its Complete Path.

Absolute Path Vs Relative Path Differences in Web Address or Web Hyperlink has been discussed at top of this article.

Absolute Path Vs Relative Path: Which One To Choose For SEO?


Absolute Path is preferred for Search Engine Optimization even for internal links. For Custom Websites, you can do it yourself and CMS Websites allow it to happen automatically. As WordPress automatically generates Absolute Path URLs for links that are not embedded in the content.

Avoid using Relative Paths for your Site because sometimes links get incorrect and Only one incorrect link is enough to destroy your website.

Relative URLs also create problems for RSS Feeds. So, Always use Absolute Paths for your links. Use of Absolute Paths in SEO ensures correct link creation and content displays correctly.

Using Absolute Paths for Images specify you the owner of the property which reduces Content copy or Content Duplication.

Leave a Reply

%d bloggers like this: