vidriduch
vidriduch

Reputation: 4863

html <base> tag functionality misunderstood?

I have simple IIS Structure:

DefaultWebsite - landing page reachable by going to 192.168.1.5

testapp - web application reachable by going to 192.168.1.5/testapp

testapp's index.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Test App</title>
    <base href="/testapp/" >
</head>
<body>
    <a href="/">Test Link</a>
</body>
</html>

I'm using base tag to set base of the app, so when clicking on Test Link I would expect just to reload the page as it is pointing to documents root. But this is not the case. Clicking on the "Test Link" takes me to the index of DefaultWebSite.

Is this the way how this should work or am I not understanding the the base tag correctly ...

Upvotes: 2

Views: 58

Answers (2)

dhh
dhh

Reputation: 4335

The base tag only applies for all relative URLs. So, with the base tag like <base href="/testapp/"> the following would apply.

<a href="/index.html">link</a>

would refer to the DefaultWebsite.

But

<a href="index.html">link</a>

Would refer to your testapp.

Upvotes: 1

Captain Giraffe
Captain Giraffe

Reputation: 14705

base only comes into play on relative hrefs. So

<a href="/">Test</a>

is not affected by base at all.

BalusC has a very informative answer on its uses at https://stackoverflow.com/a/1889957/451600

Upvotes: 1

Related Questions