118

I created a GitHub pages repository. For some reason when I name it https://[username].github.io, it doesn't work, but it works when I name it https://[username].github.io/index.html.

Why?

Aryan Beezadhur
  • 4,503
  • 4
  • 21
  • 42
Ratan Senapathy
  • 2,148
  • 2
  • 10
  • 14
  • 1
    did you enable it in the settings of that repository ? – zeekhuge Jul 27 '17 at 23:39
  • 1
    What do you mean? I am able to access it if I give index.html as a suffix right. Is there any setting on github to do that? – Ratan Senapathy Jul 27 '17 at 23:48
  • Some how it randomly started working. The url without the appended index.html. Maybe it just needed time for the settings to take effect maybe? – Ratan Senapathy Jul 27 '17 at 23:53
  • What do you mean by "when I name it"? What is "it"? – Nico Haase Oct 20 '20 at 07:46
  • The issue resolves by adding `baseurl: /` property to `_config.yml` – Alexander Zhak Dec 28 '20 at 12:59
  • What solved it for me: 1) adding the .nojekyll comment (see other posts below) 2) adding `publishDir: docs` in the config.yaml. Then rebuilding the website - this will populate a docs folder with the html & making sure that github pages build on the docs folder. – A.Fischer Jan 24 '22 at 19:10

15 Answers15

78

It got fixed automatically. I just had to wait for a while for the settings to take effect.

Ratan Senapathy
  • 2,148
  • 2
  • 10
  • 14
58

Pushing a second commit fixed this for me.

Seeing other answers where changes fix this, my guess is that you need to trigger a few of deployments to get it to work.

Every push will trigger a new deployment. You can track deployments at https://github.com/username/username.github.io/deployments.

CGK
  • 2,662
  • 21
  • 24
  • 6
    Push again works for me. seems like problem with some cache – Jianwu Chen Oct 03 '19 at 18:19
  • 2
    Pushing another commit also fixed it for me. If it is a cache, it's gotta be something on github's end as even with a hard refresh that should clear caches (`Shift+ctrl+R`) the page without the `index.html` was still 404-ing for me. – MoralCode Dec 09 '20 at 07:27
  • This is still a problem in 2021 in case anyone was wondering. It also happens if you push a commit that deletes your index.html and then push another commit to put it back. – weberc2 Jan 29 '21 at 04:44
  • 1
    I just re-run my build workflow and it got fixed. – Hans5958 Mar 08 '21 at 01:01
  • Same here! Pushing second commit fixed it. Thanks! – Al Johri Apr 07 '21 at 11:36
  • the deployment tracking thing gives me a 404. I think this has been moved into the actions tab for the repo – Maslow Dec 05 '22 at 17:26
33

If you don't use Jekyll, the workaround is to place a file named .nojekyll in the root directory.

el2e10
  • 1,518
  • 22
  • 22
14

My index.html had the following DOCTYPE setting:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" http://www.w3.org/TR/html4/strict.dtd">

Changing it to:

<!DOCTYPE html>

Fixed the issue for me.

Dakshinamurthy Karra
  • 5,353
  • 1
  • 17
  • 28
14

Faced this today (Oct-06-2019)

I double-checked every setting, all of them, didn't fix issue for me unless I changed some content in my index.html file. I also added some files to the repo to make it "alive" but in vain.

So, In my case, I opened up my index.html right in the browser, clicked on edit and added a single word, commit to master branch, refreshed and it took less than 5 seconds and it was up again.

P.S. I tried pretty much all solutions given anywhere nothing else worked for me.

Mujeeb Ishaque
  • 2,259
  • 24
  • 16
14

I also encountered the same problem today (05/28/2020). Suppose that you have done everything right (instructions in https://pages.github.com/), you should have a repo named username.github.io and index.html set up.

What worked for me was that I chose a Jekyll theme. First, go to Settings of the repo. In GitHub Pages section, look for Theme Chooser then click on Choose a Theme. It will redirect you to a GitHub page that has multiple themes that you can choose from. Choose a theme that you like then click Select Theme. After doing these steps, I refreshed my username.github.io and the page worked correctly.

tonyminhnguyen
  • 163
  • 1
  • 7
7

This happened to me and as soon as I did another commit the issue resolved itself. I just added a space to the index.html file in my dist folder, committed and pushed that change to my gh-pages branch and BAM! Now I can access username.github.io/repository/index.html by just going to username.github.io/repository.

Patrick Graham
  • 972
  • 8
  • 18
5

I had this exact same problem. If you try the link found in the designated repo > Settings > GitHub Pages after an hour after posting all your code, the GitHub page will work.

Jiovan Melendez
  • 719
  • 1
  • 6
  • 8
3

Similar problem. I had to create random change to my html, go through the git add/commit/push process. That fixed it for me! Now I can access to my page without having to add .html at the end of the url.

memoev
  • 86
  • 3
3

If you are not using Jekyll, delete the _config.yml file from the repository. This fixed the issue for me.

You may also try to push the local repository again.

j3ff
  • 5,719
  • 8
  • 38
  • 51
Aditya Bandal
  • 41
  • 1
  • 4
1

Pretty late to the party but here is how I fixed it for myself today.

  1. Go to settings for your repository: You can find Settings tab in your repo page.

  2. Scroll down to GitHub Pages section on the settings page.

  3. In the panel, you will have a Source info that states : 'Your GitHub Pages site is currently being built from the gh-pages branch'.

  4. However, in my cases, all code was in master branch. So I selected the branch from dropdown as master and in merely a minute, it was published successfully.

Peter
  • 10,492
  • 21
  • 82
  • 132
1

I had a similar problem for the private repository. My Git project contained index.html in root but the page did not display under http(s)://<username>.github.io/<projectname> path.

The solution for either way (public repository or not) is in enabling GitHub pages in project repository settings under 'GitHub pages'.

However, be aware that enabling pages under private repository make the .html files public.

Andrej Buday
  • 559
  • 5
  • 14
1

I encountered the same issue on deploying automatically a bookdown page from the gh-pages branch with Github Actions:

When I tried to access the url proposed by Github in the GitHub Pages section of the repository settings https://<username>.github.io/<reponame>/

I got a Error404: Page not found response.

However, manually adding "index.html" at the end of the url displayed the page. https://<username>.github.io/<reponame>/index.html

Adding manually a CNAME file with the following content to the gh-pages branch solved the issue permanently:

 https://<username>.github.io/<reponame>/index.html

It's more a workaround though...

EDIT:

Adding a CMAKE file solved the problem only temporarily as it was removed upon invoking the gh actions workflow. Either:

i) change gh-actions workflow to create the CMAKE file at the end (still a workaround...)

or how I could solve it in the specific case of using bookdown:

ii) in the YAML header of the index.Rmd file, I added

url: "https://<username>.github.io/<reponame>/"
Mat D.
  • 453
  • 6
  • 15
1

There is also a more subtle problem which causes this issue. If you are using image files with huge sizes in the index.html, this problem occurs. Reducing the size of the images being loaded solved this problem for me.

Dharman
  • 30,962
  • 25
  • 85
  • 135
0

In Settings>Github Pages, make sure that the branch selected there is the same as the one you are working with. I had the same problem and the branch was master instead of main so I changed it and it is fixed now.