Absolute and relative URLs

The URI general syntax allows a resource to be specified as an absoluteor a relative URL. Absolute URLs identify the protocol http://, the host, and the path of the resource, and can be used alone to locate a resource. Here’s an example absolute URL:

http://webdesign.onyou.ch/2010/12/26/absolute-and-relative-urls/

Relative URLs don’t contain all the components and are always considered with respect to a base URL. A relative URL is resolved to an absolute URL, with respect to the base URL. Typically, a relative URL contains the path components of a resource and allows related sets of resources to reference each other in a relative way. This allows path hierarchies to be readily changed without the need to change every URL embedded in a set of documents.

The following table shows several relative URLs and how they are resolved to the corresponding absolute URLs given the base URL http://onyou.ch/a/b/c.html?foo=bar.

Relative URL Absolute URL with respect to http://onyou.ch/a/b/c.html?foo=bar
d.html http://onyou.ch/a/b/d.html
e/d.html http://onyou.ch/a/b/e/d.html
/d.html http://onyou.ch/d.html
../d.html http://onyou.ch/a/d.html
#xyz http://onyou.ch/a/b/c.html?foo=bar#xyz
./ http://onyou.ch/a/b/
../ http://onyou.ch/a/

Share this

The Author

admin - Hello, my name is Simon, I’am 25 and I’m a software and web developer. My interests span all aspects of programming and development, including ASP, JavaScript, AJAX, PHP, .NET, Java, C#, C++, Objectv-C, Flash, Cocoa, SQL, XML and everything in between. www.simra.ch

Leave a Reply

*
 
© 2010 onYou GmbH. All Rights Reserved