Home
Support Forums

Redirects with Hugo

Hello! I can’t seem to figure out the right way to get redirects to work on my help center. The below examples are just tests, ideally I’d like to redirect a subfolder to a new subfolder.

  • I’ve tried storing them in _redirects, _redirects.txt, and netlify.toml.
  • I’ve tried using the following build commands:
    • hugo && cp _redirects /_redirects
    • hugo && cp _redirects public/_redirects
  • I’ve tried with and without 301 and 301!
  • I’ve tried using full URLs

_redirects examples

Note: no matter how many redirects i put in the _redirects file, the log says 1 redirect rule successfully processed.

/mytest2    /developers 301!
/news   /blog 301

https://deploy-preview-129--bolt-docs.netlify.app/mytest2   https://deploy-preview-129--bolt-docs.netlify.app/developers 

https://deploy-preview-129--bolt-docs.netlify.app/mytest3   https://deploy-preview-129--bolt-docs.netlify.app/shoppers 301 

https://deploy-preview-129--bolt-docs.netlify.app/mytest4   https://deploy-preview-129--bolt-docs.netlify.app/merchants 301!

netlify.toml examples

Note: the log says 3 redirect rules succesfully processed.

[redirects]]
  from = "/old-path"
  to = "/new-path"
  status = 301
  force = false

[[redirects]]
  from = "/releases"
  to = "/shoppers"
  status = 301
  force = true

General Questions

  • does this kind of testing work in deploy previews?
  • for _redirects, does the number of spaces or tabs inbetween matter?
  • does it take a certain amount of time to work and i need to wait to validate?

Hi @LBLiii

Can I assume you have read through the Redirects and rewrites docs?

If you download your site as outlined here you should see a _redirects file with any processed redirects in it.

Redirects are processed during build and available when your site is.

In my experience, no.

Yes.

So it might have tried processing the other rules but was unable to. You could try deploying with one rule, then then two, and so on. Tedious yes, but might help find the issue.