Custom Search
 


Absolute Path and Relative Path Explained



Web pages consist of web links. The links can send users either to external sites or to pages on the same site which is internal links. Internal links can be created by using either absolute path or relative path.

Relative path is a path relative to the current page's path location. Current page is the page that contains the URL link.

Absolute path is a path that starts with domain URL. Absolute path can be a full path or take the form of a short version. The short version always starts with a forward slash, which is the part of a full URL without the domain name part.

Recommendation

When you link to a page on your own website, always use the short version of an absolute path or use relative path. This speeds up page load time because you have told web server that the linked page is located on the same site.

Another advantage of avoiding the use of full version of absolute path is that if you ever need to change domain name for your site, the links are not going to break. This is because you didn't hard code your old domain name into the links with full version of absolute path.

When you link to a page on another website, you can only use full absolute path. That is a full URL.

Absolute Path and Relative Path Examples

The following table shows you examples of the various paths. We assume current page location is:

http://www.site.com/products/sales/july/

Type Level Absolute Path (full version) Absolute Path (short version) Relative Path
Directory Current http://www.site.com/products/sales/july/ /products/sales/july/  
File Current http://www.site.com/products/sales/july/index.html /products/sales/july/index.html  
Directory 1 Level Up http://www.site.com/products/sales/ /products/sales/ ../
File 1 Level Up http://www.site.com/products/sales/summary.html /products/sales/summary.html ../summary.html
File 1 Level Up http://www.site.com/products/sales/services/index.html /products/sales/services/index.html ../services/index.html
Directory 2 Level Up http://www.site.com/products/ /products/ ../../
File 2 Level Up http://www.site.com/products/demo.html /products/demo.html ../../demo.html
File 2 Level Up http://www.site.com/products/category/index.html /products/category/index.html ../../category/index.html
Directory 3 Level Up http://www.site.com / ../../../
File 3 Level Up http://www.site.com/index.html /index.html ../../../index.html
File 3 Level Up http://www.site.com/aboutus/index.html /aboutus/index.html ../../../aboutus/index.html
Directory 1 Level Down http://www.site.com/products/sales/july/images/ /products/sales/july/images/ images/
File 1 Level Down http://www.site.com/products/sales/july/images/product1.jpg /products/sales/july/images/product1.jpg images/product1.jpg

When you link to a page located two directories up from the current directory, it will be like this:

  • Short version of absolute path: <a href="/products/category/index.html">

  • Relative path: <a href="../../category/index.html">

That's because your current page location is http://www.site.com/products/sales/july/index.html


Copyright© GeeksEngine.com



Related Articles:

1.The Difference Between Dynamic URLs and Static URLs
2.Robots Meta HTML Tag Syntax Explained
3.What If You Don't Want Your Pages To Be Crawled and Cached by Search Engines
4.What Robots.txt is And Search Engine Robots Explained
5.The Right Domain Name Drives More Website Traffic


Other Recent Articles from the Web Development category:

1.Connect to a MySQL Database from PHP version 5 or later versions
2.Java / JSP lost session value on redirect - FIXED
3.Fix the problem with PHP5 XML removeChild() method
4.How to integrate PHP HTML Help .chm file with Crimson Editor
5.How to Connect to a MySQL Database from PHP (version lower than PHP 5.0.0)
6.Use MySQL String Functions to Build Printable ASCII Character Chart
7.Five ways to create include path for PHP
8.How to use Date and Time data as integer value in PHP and MySQL

Copyright © 2024 GeeksEngine.com. All Rights Reserved.

This website is hosted by HostGator.

No portion may be reproduced without my written permission. Software and hardware names mentioned on this site are registered trademarks of their respective companies. Should any right be infringed, it is totally unintentional. Drop me an email and I will promptly and gladly rectify it.

 
Home | Feedback | Terms of Use | Privacy Policy