Saif Al Falah
Saif Al Falah

Reputation: 358

Relative link not working

I'm working on a project and I'm using bootstrap. I'm configuring a nav bar. This is the code for one item in my nav bar.

<li class="active"><a href="/aboutus.html"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> About</a></li>

When I load the index.html instead of pointing it at 'C:/Users/.../about.html' it's pointing at 'file:///C:/aboutus.html'. Obviously, I'm getting an error 404 here.

Now when I change the code to:

<li class="active"><a href="../project/aboutus.html"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> About</a></li>

It's now pointing to the right location and I'm able to access the page.

What is happening?

Edit: Yes, I'm running it locally. The same is happening to every file here and in rest of the file system. The file tree is:

../project/aboutus.html
../project/index.html
../project/css/<contains standard bootstrap files>
../project/fonts/<contains standard bootstrap files>
../project/js/<contains standard bootstrap files>

Edit2: It's also working fine if I just add a single dot before the relative path. Like this:

<li class="active"><a href="./aboutus.html"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> About</a></li>

Upvotes: 0

Views: 7475

Answers (1)

Vatre
Vatre

Reputation: 21

Links beginning with a "/" are absolute paths. In your case you should remove it. Try with :

<li class="active">
    <a href="aboutus.html"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> About</a>
</li>

Upvotes: 1

Related Questions