Issues with Redirects

Hi all -

I am running into a couple of issues with redirects that I have been struggling to resolve. No redirect seems to work using netlify dev. Here’s a simple redirect that works in production but not locally with dev:

[[redirects]]
  from = "/blog/"
  to = "/index.html"
  status = 302

I have tried using both netlify.toml and _redirects but neither seems to work locally. The site is built with Hugo and I am on MacOS Catalina.

hi @remotesynth – I want to know more about redirects now as well.

I was pushing a gatsby site – and having issues with redirects. Then, I built locally – and dragged the public folder to netlify – which seemed to work. Which meant something was breaking during the ‘netlify-build’ after they pulled the repo from github using the ci/cd connection to github.

Then, I discovered a gatsby plugin – I wonder, does Hugo have a plugin specific for netlify that helps with redirects and headers?

It should be straightforward, but I’m thinking the these advanced static-site generators are doing lots of work in the build phase.

Also, make sure the _redirects folder is in the proper location after the local build as well.

The main thing to keep in mind about building your site on our CI and deploying redirects with it is that you need _redirects in the root of your built site (next to index.html or in gatsby and hugo’s case it could also live in the static directory) OR you need netlify.toml in the base of your repo after build. Some site generators don’t like it when files start out in the destination directory (hi Hugo!). Gatsby does have redirect plugins but not sure exactly how they work and they aren’t required for either site builder.

If you are still seeing troubles with netlify dev, could you link us to a repo that demonstrates the reproduction case? I’d think that either specification should work there (as Brian says, would be necessary to have _redirects in the right place locally too)

Thanks! The issue I had was with the redirect was using a Netlify.toml on Hugo. The contents are what I pasted above. It worked on Netlify but not locally on dev. Here’s a slightly more complicated version using role based redirects, but it also does not work on dev. https://github.com/remotesynth/gated-content-example

Hi @remotesynth if you’re testing with the same exact code locally and it’s not working, but it works in production, then that sounds like a bug. Just to be clear, do you have custom netlify dev settings in your netlify.toml and is the cli reading them? I ask to make sure that the cli is picking up on the netlify.toml.

@futuregerald Thank for the response. It’s definitely seeing it as it picks up on the build information for functions, for example.

Thanks, netlify dev is still in beta. I recommend opening an issue about this bug in the repo: https://github.com/netlify/cli