Rob H
Rob H

Reputation: 53

Why do some bad relative URLs work?

Some images that look like they shouldn't work (bad relative URLs), are being displayed in the browsers.

For example, on this page:

http://www.jbprince.com/pastry-bags-tips-and-brushes/pastry-tube-set-55-pc.asp

This image is displayed correctly:

<img src="images/B603A.jpg"/>

By my reckoning, the absolute path should be:

http://www.jbprince.com/pastry-bags-tips-and-brushes/images/B603A.jpg

which doesn't resolve. But it displays in the browser, and if you click "copy image URL" it shows:

http://www.jbprince.com/images/B603A.jpg

Shouldn't images be a subdirectory of pastry-bags-tips-and-brushes as there is no preceding slash? What am I missing here?

Upvotes: 1

Views: 101

Answers (2)

evil otto
evil otto

Reputation: 10582

The page has a base url set (with the base element in the head section), which changes how relative links/images/... are resolved.

Upvotes: 0

zw324
zw324

Reputation: 27210

Note this line in the <head>:

<base href="http://www.jbprince.com/">

So this is not a bad link, since

<img src="images/B603A.jpg"/>

is appended to the base (see base), thus results in

http://www.jbprince.com/images/B603A.jpg

Upvotes: 4

Related Questions