Software, your way.
burger menu icon
WillMaster

WillMasterBlog > HTML

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Link URLs

This article describes various ways to construct link URLs.

Of course, you know how to construct a link. I'll show the code anyway in order to have something to reference.

<a href="URL">[image/text]</a>

The URL may be the full, absolute URL. Or, a partial URL may be provided to let the browser complete it.

Here are various ways the link URL for the web page can be constructed. Following these is information about them.

https://example.com/books/info/index.php
https://example.com/books/info/
https://example.com/books/info
http://example.com/books/info

//example.com/books/info

/books/info/index.php
/books/info/
/books/info
books/info

../info
./info

In the box above are 11 URLs in 4 categories:

→ The first 4 URLs in the above box are absolute URLs.

→ The next 1 is a URL relative to the protocol used to view the current web page.

→ The next 4 are URLs relative to the web page being viewed.

→ The last 2 are relative URLs with directory tree notation.

Each category has an explanation:

  • 4 Absolute URLs:

    These are link URLs that begin with https: or http: protocol. If the URL does not include a file name, the server will serve whatever is its default (usually, index.*).

  • 1 URL relative to the protocol:

    This is similar to an absolute link URL. The difference is that the browser provides the protocol to make it an absolute URL. The protocol the browser provides is the protocol of the web page that the browser has loaded and where the link is found.

  • 4 URLs relative to the web page:

    The link URLs are relative to the document root of the current web page or relative to the subdirectory where the web page is located. (The document root is the directory where the main or index page for the website is located.)

    When the relative URL begins with a slash ("/") character, the URL is relative to the document root. Otherwise, the URL is relative to the subdirectory where the web page with the link is at.

    Relative URLs can link only to locations within the domain where the web page is located.

  • 2 Relative URLs with directory tree notation:

    Relative link URLs (see previous list item) can also have directory notation. Directory notation is one or two dots followed by a slash ("/") character.

    If the directory notation is ./ (one dot and slash), it means the same thing as relative URLs without a slash prepended — the URL is relative to the subdirectory where the web page with the link is at.

    If the directory notation is ../ (two dots and slash), it means the link URL starts with the directory further back. Relative URLs may begin with more than one ../ set, each of which tells the browser the link URL should begin still one more directory further back. Note, however, that the browser will not use a link URL beginning any further back than the document root.

    As an example, if the current web page is https://example.com/books/sale/index.php and the relative link URL is ../info, then after the directory shift the resulting relative link URL would be /books/info

The above all applies to link URLs within web pages being viewed online with a browser.

There is a caveat. If the web page is downloaded and the browser is used to view the page locally, then only absolute URLs will work. Therefore, if it is important that your web page links always will be correct, then use only absolute link URLs.

(This content first appeared in Possibilities newsletter.)

Will Bontrager

Was this blog post helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method


All information in WillMaster Blog articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

Recent Articles in the Library

Tap to Select

Find out how to make a link or button to select the content in a div or other HTML element.

Capitalizing the First Letter of Words

Here, find both PHP code and JavaScript code to capitalize the first letter of a word.

Fixed-position Table Header

During a vertical scroll, the table header scrolls out of view -- unless the header is fixed in position.

Simple Floating Menu

When not needed, the menu on the left side of a web page retracts to be out of the way. Tap it and it expands.

CSS Drop Shadows for Images

Images can be given drop shadows using pure CSS.

Ajax File Upload

Learn how to upload a file as soon as a file upload form field is given a file to upload.

Another Form Spam Prevention Technique

This technique should stop much or most of the form spam you are experiencing, perhaps even all of it.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC