How does web servers serve Media with relative path?

Hello

I have been trying to find an answer to this for long but no dice so finally posting it here hoping someone can help me understand the concept.

Consider the following HTML code:

<!–index.html–>


<html>
<head>
<title>Welcome</title>
</head>
<body>
<img src="images/banner.png" />
</body>
</html>

The Scenario:
Suppose I have an apache web server running on a machine and the web root folder has the above index.html as well as the banner.png image sitting under the “images” directory under web root. A user requests the page from a remote location using the server’s domain
phantom007.com
the user’s browser will render the html page along with the image.

Now the question(s).
Since the image source in the above index.html file has a relative path
images/banner.png
and not an absolute path
phantom007.com/images/banner.png
then:

  1. How does the user’s browser render the image that has a relative path in a remote location?
  2. Does the image file also gets transferred to the client’s machine?
  3. If the answer to the above is “yes”, in which medium / format does it get transferred? I mean via the headers or something else?

Thanks for any inputs.

It adds the relative path to the path of the current URL. So for your example, if someone requests [color=red][noparse]http://phantom007.com/[/noparse][/color] and there is a relative link to [noparse]images/banner.png[/noparse] then the browser will concatenate those and request [color=red][noparse]http://phantom007.com/[/noparse][/color][color=blue][noparse]images/banner.png[/noparse][/color].
Note that an absolute link doesn’t have to start with the domain, just a leading slash enough, i.e., /images/banner.png is also an absolute link.

Of course. How else is the client supposed to see it?

It will be a separate request. The browser will first download the index.html, find a reference to banner.png, and start to download banner.png as well. Every asset (css, javascript files, images) will always be downloaded separately, which is why it’s always a good idea to combine as of them as possible.

p7,

Good explanation from Rémon but let me extend that to the redirections that this board normally discusses:

RewriteRules are used to redirect a URI to another URI/URL via either a relative link (as you have asked about above) or an absolute link. If the absolute link is external (starts with http://{domain}/{path-to-file}), it’s handled as a new URL to that file. If it’s an INTERNAL absolute link, though, Apache looks to the server’s root for the {path-to-file} then to the website’s DocumentRoot. If you are careless enough to name your files etc/password (or the like), you could be causing significant security issues with your server. IMHO, it’s best to try to avoid internal absolute links … unless you know what’s at your server’s root AND do not allow visitors to enter their own URIs on your website.

Regards,

DK