38

I'm running a static blogdown site and deploy it on Netlify. I source files on GitHub, Hugo builds the site, and Netlify deploys it.

Netlify reports that the site is live (deploy log enclosed at the bottom), but when I'm trying to view my site, all I see is a Netlify error message:

Page Not found

Looks like you've followed a broken link or entered a URL that doesn't exist on this site.

← Back to our site

What could be the reason?


My GitHub Repo: https://github.com/taraskaduk/taraskaduk

My URL where the site should be: https://taraskaduk.com/

My deploy settings:

Repository: https://github.com/taraskaduk/taraskaduk
Build command: hugo
Publish directory: public
Production branch: master
Branch deploys: Deploy only the production branch and its deploy previews
Public deploy logs: Logs are public

Hugo version (I tried different ones)

HUGO_VERSION 0.37.1

My latest deploy log:

9:56:27 PM: Build ready to start
9:56:28 PM: Fetching cached dependencies
9:56:29 PM: Starting to download cache of 172.4MB
9:56:30 PM: Finished downloading cache in 1.74774892s
9:56:30 PM: Starting to extract cache
9:56:33 PM: Finished extracting cache in 2.59393707s
9:56:33 PM: Finished fetching cache in 4.428746301s
9:56:33 PM: Starting to prepare the repo for build
9:56:33 PM: Preparing Git Reference refs/heads/master
9:56:34 PM: Starting build script
9:56:34 PM: Installing dependencies
9:56:35 PM: Started restoring cached node version
9:56:37 PM: Finished restoring cached node version
9:56:37 PM: v8.11.2 is already installed.
9:56:38 PM: Now using node v8.11.2 (npm v5.6.0)
9:56:38 PM: Attempting ruby version 2.3.6, read from environment
9:56:39 PM: Using ruby version 2.3.6
9:56:39 PM: Using PHP version 5.6
9:56:39 PM: Installing Hugo 0.37.1
9:56:39 PM: Started restoring cached go cache
9:56:39 PM: Finished restoring cached go cache
9:56:39 PM: unset GOOS;
9:56:39 PM: unset GOARCH;
9:56:39 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.10.linux.amd64';
9:56:39 PM: export PATH="/opt/buildhome/.gimme/versions/go1.10.linux.amd64/bin:${PATH}";
9:56:39 PM: go version >&2;
9:56:39 PM: export GIMME_ENV='/opt/buildhome/.gimme/env/go1.10.linux.amd64.env';
9:56:39 PM: go version go1.10 linux/amd64
9:56:39 PM: Installing missing commands
9:56:40 PM: Verify run directory
9:56:40 PM: Executing user command: hugo
9:56:40 PM: Building sites …
9:56:40 PM: 
9:56:40 PM:                    | EN
9:56:40 PM: +------------------+----+
9:56:40 PM:   Pages            |  6
9:56:40 PM:   Paginator pages  |  0
9:56:40 PM:   Non-page files   | 49
9:56:40 PM:   Static files     | 39
9:56:40 PM:   Processed images |  0
9:56:40 PM:   Aliases          |  4
9:56:40 PM:   Sitemaps         |  1
9:56:40 PM:   Cleaned          |  0
9:56:40 PM: Total in 522 ms
9:56:40 PM: Caching artifacts
9:56:40 PM: Started saving pip cache
9:56:40 PM: Finished saving pip cache
9:56:40 PM: Started saving emacs cask dependencies
9:56:40 PM: Finished saving emacs cask dependencies
9:56:40 PM: Started saving maven dependencies
9:56:40 PM: Finished saving maven dependencies
9:56:40 PM: Started saving boot dependencies
9:56:40 PM: Finished saving boot dependencies
9:56:40 PM: Started saving go dependencies
9:56:40 PM: Finished saving go dependencies
9:56:40 PM: Build script success
9:56:40 PM: Starting to deploy site from 'public'
9:56:41 PM: Starting post processing
9:56:41 PM: Post processing done
9:56:41 PM: Site is live
Community
  • 1
  • 1
Taraas
  • 1,268
  • 1
  • 11
  • 20
  • 1
    Have you tried setting your baseurl in `config.toml` to your website address (ending in a trailing slash)? I haven't seen that leading to "Page Not Found" but I have seen folks talking about [it causing other problems](https://github.com/rstudio/blogdown/issues/114) – aosmith Jun 08 '18 at 02:33
  • Yes I have. In fact that's the way it was. I only tried to change it to "/" to see if it does anything. It dodn't... – Taraas Jun 08 '18 at 02:41
  • And just to be certain, your website looks fine locally when you serve the site? I have a found a few things that may be relevant but are over my head; a big difference I can see in your website is the [use of submodules](https://stackoverflow.com/questions/40449523/hugo-fails-to-build-site-saying-it-is-unable-to-find-a-theme), which could then be related to [netlify and redirecting](https://github.com/vuejs/vuepress/issues/457) (also discussed [here](https://github.com/developit/preact-boilerplate/issues/101). – aosmith Jun 08 '18 at 13:41
  • RIght, it looks great locally! And I switched to submodules yesterday and today in attempts to troubleshoot stuff (I thought that perhaps submoduling the theme would do it). The problem started before I switched to submodules. It started when I tried to stop building the site locally (another question that I posted and you answered) https://stackoverflow.com/questions/50750447/netlify-fails-to-deploy-site-after-public-is-added-to-gitignore – Taraas Jun 08 '18 at 14:12
  • 1
    Well, shoot, I'm out of ideas. The whole "redirecting" thread made me think it could have something to do with index.html, but as far as I can tell I'm using the same one for my [academic-themed website])https://github.com/aosmith16/academic). Hope you figure things out! – aosmith Jun 08 '18 at 14:36
  • Haha, thank you anyway! I did what you did and checked others' people github repos (whoever runs their site on the Academic theme) - could find anything different! – Taraas Jun 08 '18 at 14:47
  • Two questions: 1) Did you actually add your custom domain to Netlify? https://www.netlify.com/docs/custom-domains/#assigning-a-custom-domain 2) What is the Netlify subdomain of your website? – Yihui Xie Jun 08 '18 at 15:04
  • @YihuiXie, yes I did, long time ago when I first deployed the site (was building it locally back then, as I didn't know any better). Everything was wprking. I haven't changed those settings since. This is from Netlify settings. Default subdomain - taraskaduk.netlify.com; Primary domain - taraskaduk.com – Taraas Jun 08 '18 at 15:12
  • @YihuiXie my problem may be similar to this: https://github.com/developit/preact-boilerplate/issues/101 Is there any need to mess with redirects, or is this something blogdown handles in the background? – Taraas Jun 08 '18 at 15:15
  • 1
    I don't think your issue is relevant to redirects, since you don't have `static/_redirects`. I don't think it is relevant to blogdown, either, since it works fine locally. I'm out of ideas like @aosmith. You may reach out to Netlify support and see if they have any ideas. – Yihui Xie Jun 08 '18 at 17:56
  • 1
    Actually you can change the command `hugo` to `hugo -v` on Netlify, which may reveal more information. – Yihui Xie Jun 08 '18 at 17:59
  • @YihuiXie, it did reveal a bunch of info! I am getting a bunch of long WARN messages all of which start with `Unable to locate layout for ...` My understanding is that there is a problem with the theme, or rather the way I have it set up? – Taraas Jun 08 '18 at 18:16
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/172781/discussion-between-taraas-and-yihui-xie). – Taraas Jun 08 '18 at 18:33
  • @YihuiXie I got to fix the issue (see solution posted below). But I'm not sure why it didn't work, and why what I did fixed it... – Taraas Jun 08 '18 at 20:47
  • https://blog.almightytricks.com/2020/10/14/how-to-fix-404-page-not-found-error-after-build-in-angular-or-react-or-vue-js/ A nice article for resolving 404 error – Sangram Badi Oct 19 '20 at 04:35
  • Another cause of this problem was that the netlify.toml wasn't in the root directory on my side. I hope this helps. – moud Jul 15 '23 at 14:59

19 Answers19

89

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.

Adwaith
  • 1,099
  • 1
  • 9
  • 6
37

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

fool
  • 3,044
  • 20
  • 28
  • Thanks @fool! This is a comprehensive response. But I didn't manage to debug it on my own, starting fresh and going step by step. Postin my solution here separately. – Taraas Jun 08 '18 at 20:43
  • 1
    My error was creating a index.php file instead of a index.html file. I didn't know netlify only serves static content. – trinity420 Apr 17 '19 at 13:40
5

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?

Taraas
  • 1,268
  • 1
  • 11
  • 20
  • 2
    Glad you figured it out! This looks like [this issue](https://github.com/rstudio/blogdown/issues/297). I think the explanation is the very last comment. – aosmith Jun 08 '18 at 21:06
  • 1
    @aosmith You pointed to the exactly correct reason. The TOML syntax has surprised several people. I have complained about it in the footnote 23 in Section 2.2 of the blogdown book: https://bookdown.org/yihui/blogdown/configuration.html – Yihui Xie Jun 09 '18 at 00:38
4

For Angular, I was experiencing this and I found the following to work:

touch src/_redirects

This file will contain the rule below. It indicates that all requests to the server should be redirected to index.html. We also add a HTTP status code option at the end to indicate that these redirects should return a 200 status. By default, a 301 status is returned.

/*  /index.html 200

The last thing we have to do is add the below option in our angular.json und er projects > {your_project_name} > architect > options > assets. Include it in the assets array:

{
  "glob": "_redirects",
  "input": "src",
  "output": "/"
}

From https://www.smashingmagazine.com/2020/10/angular-feedback-netlify-forms-edge/

Michael
  • 591
  • 8
  • 24
3

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.

Dejazmach
  • 742
  • 8
  • 15
3

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

Commit and push to your github React Router it handles all the routes but when you visit an endpoint endpoint, netlify must know where to redirect you to. That is what we are specifying in the _redirects file.

devELIOper
  • 625
  • 5
  • 7
2

Angular 8 and now Angular 9 publish in dist/{project name}, that is the foldername to type, not just dist like in previous releases. If you specify only dist it will look for index.html in the wrong directory and the result will be a "Page not Found".

Nicola
  • 101
  • 1
  • 9
2

I created a file named netlify.toml in the same level that package.json or root folder with this inside and works!

///netlify.toml

[build]
  command = "CI='' npm run build"
  publish = "/build"
  base ="/"

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200
nativelectronic
  • 646
  • 4
  • 11
1

Faced this problem. My solution was to set the correct build path to publish declaration inside the netlify.toml file. The new netlify automated deployment process uses this file to deploy projects from repositories.

bir_ham
  • 513
  • 5
  • 19
1

create index.html in root directory and point to the index file in public folder using the following code

<meta http-equiv="Refresh" content="2; url=public/index.html" />

1

I had exactly the same problem when I deployed my react app on netlify, it fixed when I did the following:

  1. in the root of your project create file and name it netlify.toml
  2. past this code snippet into it and save it( make sure the indentation is like this!!
[build]
  command = "npm run build"
  publish = "/build"
  base ="/"

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

push this change to your github/ or bitbucket or wherever you are hosting you code.

-if you are already connecting Netlify to your project repository, an automatic deployment process will start and you can see it on your Netlify project page

Yusuf
  • 2,295
  • 7
  • 15
  • 34
0

name your main HTML file as index.html instead of any other name.

0

enter image description here

I made sure the 'publish directory' and the build folder are named identically. Then I pushed the changes that @Adwaith suggested above. Big thanks to @Adwaith your input was a lifesaver.

L. Theodore Obonye
  • 1,221
  • 1
  • 6
  • 9
0

In my case I had (vue3 application) to upload the whole of the build directory (dist/) instead of just the files. That worked for me

Venkatesh A
  • 1,875
  • 1
  • 19
  • 23
0
title: 'Tezster Dart',
  tagline: 'A flutter package which provides the functionalities to play around with tezos dApps',
  url: 'https://site-name.netlify.app',
  baseUrl: '/',
  onBrokenLinks: 'throw',
  onBrokenMarkdownLinks: 'warn',
  favicon: 'img/favicon.ico',
  organizationName: 'Tezsure', // Usually your GitHub org/user name.
  projectName: 'Tezster_dart', // Usually your repo name.

If you have not updated url in docs/docusaurus.config.js that could be issue. Fix it by add url: 'https://site-name.netlify.app', and make sure it doesn't end with /. In my case it wasn't working because of / in the end.

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 20 '21 at 06:15
0

The only two reasons I could think of why, is because:

  1. .html file is not named index, your HTML file should always be index.html, at least the main/home page only (if your project is multiple webpages).

  2. Make sure you don't have each single file in a separate directory, I've seen this happen before, it causes issues.

CodeNKoffee
  • 13
  • 1
  • 4
0

for this issue "Page Not Found Looks like you've followed a broken link or entered a URL that doesn't exist on this site.

Back to our site

If this is your site, and you weren't expecting a 404 for this path, please visit Netlify's "page not found" support guide for troubleshooting tips".


  1. first the main cause of the problem is first the file named incorrectly example : exercise1.html will not recognized in netlify..

  2. It should be named as index.html

why because? web server can be configured to recognize any file you want as the default for that site. That being the case, it's still a good idea to stick with index. html or index. htm because it is immediately recognized on most servers without any additional configuration.

DSRVALLI
  • 1
  • 2
0

To solve the issue of Netlify page not found errors when refreshing a page, one solution is to create a file named "_redirects" in the public folder and write "/* /index.html 200" in that file. This will tell Netlify to redirect any requests that it doesn't recognize to your index.

html file, which should prevent the page not found error when refreshing a page.

Soad Anam
  • 1
  • 1
  • Could you clarify the last line of your answer? – user1987607 Apr 21 '23 at 09:50
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 21 '23 at 09:51
0

Inside the root folder (same level as you package.json file), create a new file named netlify.toml, with the following content:

[[redirects]]
from = "/*"
to = "/index.html"
status = 200

Then push your changes to make a fresh deploy.

omzer
  • 1,200
  • 11
  • 14