Relative vs. Absolute URL

Quotation Graphic  The most useful URL path is the relative path. The relative URL points to a file or directory in relation to the present file or directory (folder). Relative URL's help in web site maintenance. It is easy to move a file from one directory (folder) to another, or a web site from one domain name to another. And you don't have to worry about updating the link(s) or the src (img) path(s).  Quotation Graphic

Relative URL

Keep It Simple Stupid (KISS): If you are loading a file / image / etc. that is in the same directory as the source file, just use the file name. If the html file is in the top directory and need to link to an image in that directory, the relative URL would be <img src="top.gif" />. This is the very basic - simple example of a relative path because the file and directory are both in same place. In other words, no path info is required if the files are in the same directory. ( very convenient and easy to manage).

For next level: To access a sub-directory below the top directory - do NOT use the preceding slashes. For example, if you Home page is the index.html and the logo (ad_th1.jpg) image is in the images directory, use:
<img src="images/ad_th1.jpg" /> (note the omission of the slash :)

For more details - Here is example on a web server (where the web root is public_html)

Root (public_html)
.......index.php
.......header.jpg

.... images
......ad_th1.jpg

.... articles
......path
......path.php (this page)

For this page, the current page is the path.php file inside the article directory. Therefore, the relative path to this page is
/articles/path.php

Article Dashboard Installation Then to load the ad_th1.jpg image (our signature button), the relative path to the image is ../images/ad_th1.jpg

Which means the ad_th1.jpg image is in a directory one level up from this path.php file - then down into the 'images' directory.

The two dots .. instruct the server to move up one directory. Therefore one sets of ../ moves up one level to the root directory (public_html) - then opens the images directory and loads the ad_th1.jpg file.

Of course, if the image had been in the articles directory the relative path would be
../articles/imagename.jpg

Relative path is really easy to understand just by reviewing the basic definition:
A relative URL points to a file or directory in relation to the present file or directory.

Absolute URL

An absolute URL is the URL most people already understand. It is the complete path including the domain - file name. Example: http://www.adinstall.com/images/ad_th1.jpg specifies an image file (ad_th1.jpg) located in the images directory, for the www.adinstall.com domain. This type of URL is what your must use when you want to link (or load) a file that is on another server.

Another example is the absolute URL of this page (which is also the Address / Location of the file) = http://www.adinstall.com/articles/path.php

Absolute vs. Relative Server Paths

Absolute Paths

Paths are used ON THE SERVER. Usually inside a script. The absolute path is the "full path". It is the path that contains the top directory (usually home) - the username - the root directory (usually public_html) - the sub directory (or file name) For example
/home/username/public_html/cgi-bin/test.cgi
This is the absolute path to the text.cgi file in the cgi-bin directory

BTW: /home/username/ would put you in the root of your account. An section that is NOT accessible via WWW (browser) - this is where mail files, password files, etc (other protected files) are stored on the server. You seldom need this path since you are working with web pages and need path info to the public_html (www) directory ( your root directory FOR the web)

Example of other useful path information shows the path to shared files on the server. For example the path to perl on the server:
/usr/bin/perl
Path info of this type are supplied by the host when you need it for scripts. In most cases, the cPanel account displays this info for the client. Along with path to 'date' 'sendmail' etc that are required by many scripts.

Relative Path

Relative Path may be a misnomer. It is actually like the relative url i.e. it is normally 'relative' to the public_html directory (which is the root directory for the web site / not the root of the server). However, it could be relative to the upper directories (home). But in actually use, the relative path is seldom used - even in scripts. And if it is required, the script writer may NOT use the name - relative path. It may be referred to as a non-absolute path, a direct path, a path to a file, etc. Bottom line - is that scripts that refer to the relative path - really mean the path to files below the www root (usually public_html). So it is usually the same as the relative URL. And in actual practice it's not 'usually called' a relative path. It's more likely to be referenced as the 'path to files'

Would like to host your own article directory?
Article Dashboard Download Download Article Dashboard now.

Script Installation Articles Index  Back to Articles
What's New? Web Support Solutions best autoresponder script The BEST Autoresponder.


Don't Be A Victim Of Accidental Plagiarism...Click Here Now And  Get FREE Unlimited Duplicated Content Searches and Minimize Your Risk Of Using Copyrighted Materials!

Link Machine, Link Directory Script


Eco-Friendly Hosting