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

In my project, users can enter the URL of a website, and the system sends and retrieves all the images from that website. Since the src image may be relative, the system "normalizes" it, therefore:

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

Now take a look at this page if you can:

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

If you 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 is not. This is http://www.presentkuriren.se/prodbilder/large/JJI10002.jpg , and all browsers seem to understand this and display it correctly ...

I am a little puzzled and feel that I am missing something obvious ... please point this out to me!

+6
source share
1 answer

In the <base /> in the head:

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

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

+10
source

Source: https://habr.com/ru/post/901607/


All Articles