r/github • • 13d ago

Question How can i configure my github pages site to show whats in a folder on my repo instead of a 404

Ok, this is a bit confusing to explain, but ill try.

Alot of the time i come across these websites that host files that usually say "Index of (file structure)" and show all the folders and files on the directory in a website, like this: (image 2)

But Github Pages doesnt really do that, it just gives you a 404 as if nothing is there. ive been spending days trying to figure out how to make it *not* just give some 404, so ive come here as a last resort.

Any help is absolutely appreciated!

1 Upvotes

5 comments sorted by

4

u/GiggleSamurai 13d ago

Those "Index of /" pages are made by web servers like Apache or nginx (autoindex), and GitHub Pages is a static host with no such option. To get a listing you have to commit an index page in each folder that links its files, which a GitHub Action can generate for you on every push.

3

u/ImDevinC 13d ago

You want GitHub pages: https://pages.github.com/. That being said, I'm not sure if GitHub pages provides an index list like that, so you might have to use GitHub actions to generate it when there's a file change. That being said, this isn't really a good use for GitHub. People can already see all the files when they open the GitHub page. Is there a specific problem you're trying to solve?

3

u/Impossible_Cod9831 12d ago

GitHub Pages does not generate directory listing pages (similar to Apache or Nginx "Index of" views) out of the box, as it is strictly designed for serving static web files.

To display a directory's contents through GitHub Pages, you typically need to include an index.html file within that folder or utilize a static site generator to compile an index page. Alternatively, for standard repository file browsing, navigating the file tree directly via the GitHub repository view is recommended.

2

u/corkiejp 13d ago edited 13d ago

You need a 404.html at the root of your repo, and where you saw the above index of directory is done by some scripts on the repo itself. Have a look for a file like that on that repo and you may learn how it is done?

https://docs.github.com/en/pages/getting-started-with-github-pages/creating-a-custom-404-page-for-your-github-pages-site

On my own repo, i have a simple 404.html that redirects to homepage on errors? example of no existing link: -

https://corkiejp.github.io/test/

Edit:- this maybe the answer your looking for? https://github.com/marketplace/actions/directory-listing

1

u/lajawi 11d ago

I'm baffled that your web searches haven't led to any potential solutions. When I searched for "github pages directory listing", all the top results listed many different solutions, some I would recommend, others I wouldn't. Any ways, here's a non-exhaustive list of potential solutions:

  • Use an action that generates the directory listings each time you push
  • Create the directory listings manually or let them be generated through a script locally
  • Use the GitHub API and let the visitor's browser create the listing from the results