"Page Not Found" when trying to access a site deployed on Netlify

Looks like I got it fixed. I created a new repo with a sample site, and started replacing parts of the example site with my parts to see when it breaks.

So this part of config.toml had to be excluded in order to have the site deploy normally again:

[permalinks]
    post = "/:year/:month/:day/:slug/" 

I'm not sure why - it's always been there, and it worked when I built my site locally, but didn't want to work once I added public folder to .gitignore and let hugo build my site.

Any ideas why is that?


If you see "Not Found" error while directly browsing to a specific path, For eg: https://yourdomain.com/something , this might be helpfull (ReactJS):

In your public folder (folder which contains index.html) create a file called _redirects with no extension. Then, type the following inside it:

/* /index.html 200

Now save, commit, push and publish. :)

Reason for "Not Found" is because, when using router eg: React Router it handles all the routes but when you directly goto an endpoint, netlify must know where to redirect you. That is what we are specifying in the _redirects file.


If you are using Angular 8 you need to supply the publish directory value by reading from the angular.json build outputPath which is dist/{project-name} and if you are using older versions, it should be dist which is the value of outDir that you can read from .angular-cli.json.


Disclaimer: I work on the Support team @ Netlify

It's always allowed to reach out to Netlify support about things like these, though we can only really help you debug what's different about our build process than your local, rather than debugging your source code. Let me expand on some best practices that the commenters brought up, and provide some suggestions to help you debug further that are non-obvious.

First off, as suggested (thanks @aosmith!) BaseURL should be set to / - that is a best practice and will allow your site to work locally (http://localhost) but also on Netlify - via http, https, deploy previews, and finally on other hosting providers, while proxy'd to, etc etc. Just Do It :)

Second, you could have redirects not just in a _redirects file but also netlify.toml, but I also don't think that is the problem here.

When you get a 404 at your main URL, it means that you don't have a /index.html . What the root cause of that is, I can't tell (though I can tell that hugo doesn't love it when your theme is missing and may fail to produce the content you're expecting). There are two good ways to figure out why our build isn't producing an index.html in your publish folder (public, in your case and default hugo config) though:

  1. You can download a copy of any successful deploy from the deploy logs page as shown in my screenshot, and see "what we ended up with". Typical problems here are that we have nothing (your build didn't go to public/ or that you end up without an index.html - so we correctly show a 404 without a path)

  2. You can follow the debug instructions to run our build image locally: https://github.com/netlify/build-image#testing-locally . After the build, you're still in the build shell and can go look at what's in your publish directory.

screenshot indicating deploy download location