Redirects not working as expected

Please:

  • choose at least one appropriate tag for your post (more is better)
  • a short description & what you have tried to fix it (DNS really may take up to 48 hours to propagate.)
  • build log errors, screenshots, etc
  • your Netlify instance name, for example: deluding-chances-2b123.netlify.com

Did you use the search before posting?
What about reading through our Search results for 'common issue' - Netlify Support Forums?

Netlify instance

lucid-leakey-4ba5b7

Description

Redirects not working as expected. I’m implementing client side routing in GatsbyJS in the same way I have done on this site https://shelleyexplorer.cardano.org/. That site is also hosted on Netlify. The only difference with the new implementation is the netlify.toml file is generated on build. The build output reads the redirect rules though as they do work, just not as expected.

netlify.toml

# Use this file as your netlify.toml file
# client side route redirects are auto
# generated.

[[redirects]]
  from = "/test/*"
  to = "/test/"
  status = 200

[[redirects]]
  from = "/en/test/*"
  to = "/en/test/"
  status = 200

[[redirects]]
  from = "/ja/test/*"
  to = "/ja/test/"
  status = 200

There are static html pages for /test.html, /en/test.html and /ja/test.html, the redirects above are intended to serve these files without modifying the URL, for client side routing to take over once the initial files have been served. This is to ensure direct server rendered links to /test/123/ etc. are not served with a 404 page initially from the server.

As I said before I’ve implemented the same approach on https://shelleyexplorer.cardano.org/, the only difference being the netlify.toml file is generated in this instance as opposed to a static file in the repository.

Additional resources

Screenshot of successful build outputting 3 redirect rules as expected - I cannot see how these have been processed.

1 Like

Deployment log:

4:33:40 PM: Build ready to start
4:33:46 PM: build-image version: 6b66e79d54a8f76b01392124644c3052ac0d32ef
4:33:46 PM: build-image tag: v3.3.6
4:33:46 PM: buildbot version: 2ba6f2db8150441c8469e6ae3ab3561a2c9d03fa
4:33:47 PM: Fetching cached dependencies
4:33:47 PM: Failed to fetch cache, continuing with build
4:33:47 PM: Starting to prepare the repo for build
4:33:47 PM: No cached dependencies found. Cloning fresh repo
4:33:47 PM: git clone https://github.com/input-output-hk/gatsby-starter-iohk-default
4:33:48 PM: Preparing Git Reference pull/1/head
4:33:48 PM: Starting build script
4:33:48 PM: Installing dependencies
4:33:49 PM: Attempting node version '12' from .nvmrc
4:33:50 PM: v12.16.1 is already installed.
4:33:50 PM: Now using node v12.16.1 (npm v6.13.4)
4:33:50 PM: Attempting ruby version 2.6.2, read from environment
4:33:52 PM: Using ruby version 2.6.2
4:33:52 PM: Using PHP version 5.6
4:33:52 PM: Started restoring cached node modules
4:33:52 PM: Finished restoring cached node modules
4:33:52 PM: Installing NPM modules using NPM version 6.13.4
4:34:27 PM: > sharp@0.23.4 install /opt/build/repo/node_modules/sharp
4:34:27 PM: > (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
4:34:28 PM: info
4:34:28 PM: sharp
4:34:28 PM:  Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.8.1/libvips-8.8.1-linux-x64.tar.gz
4:34:30 PM: > core-js@2.6.11 postinstall /opt/build/repo/node_modules/core-js
4:34:30 PM: > node -e "try{require('./postinstall')}catch(e){}"
4:34:30 PM: Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
4:34:30 PM: The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
4:34:30 PM: > https://opencollective.com/core-js 
4:34:30 PM: > https://www.patreon.com/zloirock 
4:34:30 PM: Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
4:34:31 PM: > gatsby-telemetry@1.1.49 postinstall /opt/build/repo/node_modules/gatsby-telemetry
4:34:31 PM: > node src/postinstall.js || true
4:34:31 PM: > gatsby-cli@2.9.0 postinstall /opt/build/repo/node_modules/gatsby/node_modules/gatsby-cli
4:34:31 PM: > node scripts/postinstall.js
4:34:31 PM: > gatsby@2.19.22 postinstall /opt/build/repo/node_modules/gatsby
4:34:31 PM: > node scripts/postinstall.js
4:34:31 PM: > gatsby-starter-iohk-default@0.0.2 postinstall /opt/build/repo
4:34:31 PM: > ./scripts/post-install.sh
4:34:33 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules/fsevents):
4:34:33 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
4:34:33 PM: npm
4:34:33 PM:  WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules/chokidar/node_modules/fsevents):
4:34:33 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
4:34:33 PM: added 1911 packages from 847 contributors and audited 29912 packages in 40.432s
4:34:35 PM: 106 packages are looking for funding
4:34:35 PM:   run `npm fund` for details
4:34:35 PM: found 4 moderate severity vulnerabilities
4:34:35 PM:   run `npm audit fix` to fix them, or `npm audit` for details
4:34:35 PM: NPM modules installed
4:34:35 PM: Started restoring cached go cache
4:34:35 PM: Finished restoring cached go cache
4:34:35 PM: unset GOOS;
4:34:35 PM: unset GOARCH;
4:34:35 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.12.linux.amd64';
4:34:35 PM: export PATH="/opt/buildhome/.gimme/versions/go1.12.linux.amd64/bin:${PATH}";
4:34:35 PM: go version >&2;
4:34:35 PM: export GIMME_ENV='/opt/buildhome/.gimme/env/go1.12.linux.amd64.env';
4:34:35 PM: go version go1.12 linux/amd64
4:34:35 PM: Installing missing commands
4:34:35 PM: Verify run directory
4:34:35 PM: Executing user command: npm run build
4:34:36 PM: > gatsby-starter-iohk-default@0.0.2 build /opt/build/repo
4:34:36 PM: > npm run clean && gatsby build && npm run build:netlify-prod && npm run build:netlify-toml
4:34:36 PM: > gatsby-starter-iohk-default@0.0.2 clean /opt/build/repo
4:34:36 PM: > gatsby clean
4:34:36 PM: info Deleting .cache, public
4:34:36 PM: info Successfully deleted directories
4:34:39 PM: success open and validate gatsby-configs - 0.022s
4:34:39 PM: success load plugins - 0.672s
4:34:39 PM: success onPreInit - 0.013s
4:34:39 PM: success delete html and css files from previous builds - 0.014s
4:34:39 PM: success initialize cache - 0.010s
4:34:39 PM: success copy gatsby files - 0.030s
4:34:39 PM: success onPreBootstrap - 0.005s
4:34:39 PM: success createSchemaCustomization - 0.004s
4:34:40 PM: success source and transform nodes - 0.121s
4:34:40 PM: success building schema - 0.270s
4:34:40 PM: success createPages - 0.023s
4:34:40 PM: success createPagesStatefully - 0.069s
4:34:40 PM: success onPreExtractQueries - 0.000s
4:34:40 PM: success update schema - 0.042s
4:34:40 PM: success extract queries from components - 0.169s
4:34:40 PM: success write out requires - 0.003s
4:34:40 PM: success write out redirect data - 0.001s
4:34:40 PM: success Build manifest and related icons - 0.001s
4:34:40 PM: success onPostBootstrap - 0.003s
4:34:40 PM: ⠀
4:34:40 PM: info bootstrap finished - 3.584 s
4:34:40 PM: ⠀
4:35:14 PM: success Building production JavaScript and CSS bundles - 34.166s
4:35:14 PM: success Rewriting compilation hashes - 0.000s
4:35:14 PM: success run queries - 34.382s - 13/13 0.38/s
4:35:24 PM: success Building static HTML for pages - 9.347s - 9/9 0.96/s
4:35:24 PM: warning app-c6ae99131e8fee5b4d8d.js is 2.56 MB, and won't be precached. Configure maximumFileSizeToCacheInBytes to change this limit.
4:35:24 PM: info Generated public/sw.js, which will precache 5 files, totaling 136495 bytes.
4:35:24 PM: The following pages will be precached:
4:35:24 PM: /offline-plugin-app-shell-fallback/index.html
4:35:24 PM: success onPostBuild - 0.139s
4:35:24 PM: info Done building in 47.641206123 sec
4:35:25 PM: > gatsby-starter-iohk-default@0.0.2 build:netlify-prod /opt/build/repo
4:35:25 PM: > NODE_ENV=production webpack --config webpack.netlify.config.js
4:35:26 PM: Hash: 4784d8e012ee5454c415
4:35:26 PM: Version: webpack 4.41.6
4:35:26 PM: Time: 703ms
4:35:26 PM: Built at: 03/09/2020 4:35:26 PM
4:35:26 PM:                              Asset      Size  Chunks             Chunk Names
4:35:26 PM: netlify.bundle.zqhyguqjtm39r02v.js  3.42 KiB       0  [emitted]  netlify
4:35:26 PM: Entrypoint netlify = netlify.bundle.zqhyguqjtm39r02v.js
4:35:26 PM: [0] ./netlify/index.js + 9 modules 3.97 KiB {0} [built]
4:35:26 PM:     | ./netlify/index.js 595 bytes [built]
4:35:26 PM:     | ./netlify/helpers.js 622 bytes [built]
4:35:26 PM:     | ./netlify/backend.js 200 bytes [built]
4:35:26 PM:     | ./netlify/collections/index.js 160 bytes [built]
4:35:26 PM:     | ./src/config.js 73 bytes [built]
4:35:26 PM:     | ./netlify/collections/metaData.js 956 bytes [built]
4:35:26 PM:     | ./netlify/collections/globalContent.js 583 bytes [built]
4:35:26 PM:     | ./netlify/collections/pages/index.js 89 bytes [built]
4:35:26 PM:     | ./netlify/collections/pages/404.js 382 bytes [built]
4:35:26 PM:     | ./netlify/collections/pages/home.js 401 bytes [built]
4:35:27 PM: > gatsby-starter-iohk-default@0.0.2 build:netlify-toml /opt/build/repo
4:35:27 PM: > node ./scripts/build-netlify-toml.js
4:35:27 PM: Skipping functions preparation step: no functions directory set
4:35:27 PM: Caching artifacts
4:35:27 PM: Started saving node modules
4:35:27 PM: Finished saving node modules
4:35:27 PM: Started saving pip cache
4:35:27 PM: Finished saving pip cache
4:35:27 PM: Started saving emacs cask dependencies
4:35:27 PM: Finished saving emacs cask dependencies
4:35:27 PM: Started saving maven dependencies
4:35:27 PM: Finished saving maven dependencies
4:35:27 PM: Started saving boot dependencies
4:35:27 PM: Finished saving boot dependencies
4:35:27 PM: Started saving go dependencies
4:35:27 PM: Finished saving go dependencies
4:35:30 PM: Build script success
4:35:30 PM: Starting to deploy site from 'public/'
4:35:30 PM: Creating deploy tree 
4:35:30 PM: Creating deploy upload records
4:35:30 PM: 17 new files to upload
4:35:30 PM: 0 new functions to upload
4:35:31 PM: Starting post processing
4:35:33 PM: Post processing done
4:35:33 PM: Site is live
4:35:58 PM: Finished processing build request in 2m11.927167475s

Hi, @lewnelson. I replied to the support ticket created about this and I’ll follow-up with you there. We can post the result of that troubleshooting here if you decide that would be helpful also.

A post was split to a new topic: Redirects work but change url in browser