Subdirectory saved in root being read as root. Solved using collections?

Have just discovered Jekyll and am building a site in localhost.

I have a bunch of .html files in a subdirectory. I saved the subdirectory in the jekyll root directory, where I have also saved the first level .html files (eg index.html, contact.html, etc).

In my browser, I click on a link in a first level page to load a file from that subdirectory (example: localhost:4000/mysubdirectory/myfile.html). That url loads successfully in my browser.

However, jekyll then injects that subdirectory as the root into every url I try to access. So when I click on a home link, instead of loading the proper url (localhost:4000/index.html ) it loads (localhost:4000/mysubdirectory/index.html). Same with every other page.

If I cannot store subdirectories in the root folder, is this solved using collections? Should I put the subdirectory folder in a collections folder and configure it? Am not building a blog.

It sounds like the href for your home link is missing a leading /. Without the slash, browsers will interpret the href as a relative URL. I.e.:

Relative URL:

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

Absolute URL:

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

That was it. Thanks !!

1 Like