Search code examples
htmlbroken-links

Links not going back a directory?


I have a website, let's call it example.com. Within this site, I have some FAQs but the person that built the site saved the FAQ pages under a directory on the site named "FAQs".

As an example an FAQ page would be located at:

example.com/pages/en/faqs/faq-page1.html.

Note the pages/en/ directory. Ideally I would like all the pages to be saved under example.com/index.html etc but I can't change this.

Anyway, when I am on any of these FAQ pages, and I try to link back to say the home page index.html the navigation won't go to the page. So for example, when I am on:

example.com/pages/en/faqs/faq-page1.html

and I try to link back to the home page

example.com/pages/en/index.html (which is where the index page is saved) the nav won't work. Instead it will try to go to example.com/pages/en/faqs/index.html.

Now I am assuming this happens because I am in the "faq" directory, but how do I go back to the root directory when linking? The code for the link is simply <a href="index.html">Home</a>. I could of course just put in the full link example.com/pages/en/index.html, which would solve this but is there another way around this?


Solution

  • You need to give a relative file path of <a href="../index.html">Home</a>

    Alternately you can specify a link from the root of your site with <a href="/pages/en/index.html">Home</a>

    .. and . have special meanings in file paths, .. means up one directory and . means current directory.

    so <a href="index.html">Home</a> is the same as <a href="./index.html">Home</a>