diff --git a/docs/docs/add-404-page.md b/docs/docs/add-404-page.md index 4bee550e0fdc3..6dbff94ecdf3c 100644 --- a/docs/docs/add-404-page.md +++ b/docs/docs/add-404-page.md @@ -3,7 +3,7 @@ title: "Adding a 404 Page" --- To create a 404 page create a page whose path matches the regex -`/404*`. Most often you'll want to create a React component page at +`^\/?404\/?$` (`/404/`, `/404`, `404/` or `404`). Most often you'll want to create a React component page at `src/pages/404.js`. Gatsby ensures that your 404 page is built as `404.html` as many static hosting diff --git a/packages/gatsby/src/internal-plugins/prod-404/gatsby-node.js b/packages/gatsby/src/internal-plugins/prod-404/gatsby-node.js index e74f4f0babdac..d1ff7d6694339 100644 --- a/packages/gatsby/src/internal-plugins/prod-404/gatsby-node.js +++ b/packages/gatsby/src/internal-plugins/prod-404/gatsby-node.js @@ -3,7 +3,7 @@ exports.onCreatePage = ({ page, store, actions }) => { // Copy /404/ to /404.html as many static site hosts expect // site 404 pages to be named this. // https://www.gatsbyjs.org/docs/add-404-page/ - if (!created404 && page.path === `/404/`) { + if (!created404 && /^\/?404\/?$/.test(page.path)) { actions.createPage({ ...page, path: `/404.html`,