Jekyll and link to internal files: page not found

An underscore in front on a directory name is fine in the case of a collection, otherwise it should not have an underscore.

But since it works locally that isn’t your problem.

I suspect you are using a subpage domain and left that part out of your question.

e.g.

Given homepage

Username.github.io/my-repo

Then you are referencing

/_research_projects/project1.md

ie

Username.github.io/research_projects/project1.html

Which is not valid.

Fix

Two things.

First set config file to match your remote environment

e.g.

url: myuser.github.io
baseurl: /my-repo/

The URL will only be used locally for prod builds and for things like sitemap. But baseurl will be used on every build or server.

The link will be shown as server started on

http://localhost:4000/my-repo/

Then second thing is to make your URL into a relative URL.

[Project 1]({{ '/_research_projects/project1.md' | relative_url }})

There is still the chance your URL is bad like a typo or the page moves.

But this is safer as it will give an error at build / server start:

[Project 1]({{ site.baseurl }}{% link _research_projects/project1.md %})

Note no quotes in 2nd case.

And then your result will be a link like this:

Username.github.io/my-repo/research_projects/project1.html

Including the subpath.

Relative links

I see you have this plugin set up and it is used on the remote set up. I don’t think it does anything relevant to this question.

Tips

BTW for SEO it is better to use hyphens as Google crawlers splits items by hyphens but seems underscore terms as a whole word.

So

research-projects/project1.md

Also make sure you are using Jekyll 3 set in Gemfile to match GitHub Pages environment. Jekyll 4 handles the link tag differently so you’ll get weirdness if you use Jekyll 4 locally and Jekyll 3 on the remote.

1 Like