Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative img src is resolved as absolute... what am I missing?

In my project users can enter the URL of a website and the system goes and fetches all images from this website. Because the src of the image can be relative, the system "normalizes" it, so:

  • an image with src="http://host.com/image1.png" becomes "http://host.com/image1.png" (no change)
  • an image with src="/image2.png" becomes "http://host.com/image2.png" (prepend host)
  • an image on "http://host.com/sub/dir/page.html" with src="image3.png" becomes "http://host.com/sub/dir/image3.png" (prepend host and path)

Now take a look at this page if you may:

http://www.presentkuriren.se/presenter/4/728/Karlek/Pasta---hjartan.html

If you have a look at the source code, the main image is implemented as <img src="prodbilder/large/JJI10002.jpg"...

This would lead me to the conclusion that the absolute path is http://www.presentkuriren.se/presenter/4/728/Karlek/prodbilder/large/JJI10002.jpg, which it is not. It's http://www.presentkuriren.se/prodbilder/large/JJI10002.jpg and all browsers seem to understand that and display it correctly...

I'm slightly baffled and feel like I'm missing something obvious... please point it out to me!

like image 277
Manuel Meurer Avatar asked Nov 16 '11 12:11

Manuel Meurer


People also ask

Why is my img src not working?

Img src Not Working That means, when a web page loads, the browser has to retrieve the image from a web server and display it on the page. The broken link icon means that the browser could not find the image. If you've just added the image, then check that you included the correct image URL in the source attribute.


1 Answers

There's the <base /> tag in the head:

<base href="http://www.presentkuriren.se/">

So all relative URLs (from images, links, ...) are relative to this one!

like image 170
ComFreek Avatar answered Nov 15 '22 06:11

ComFreek