Can 'splat' be used in Hugo Server redirects config?

In config/development/server.yaml I have the following:

redirects:
- from: /docs/pyrosim/latest/*
  status: 200
  to: /docs/pyrosim/2020-4/:splat
- from: /docs/pathfinder/latest/*
  status: 200
  to: /docs/pathfinder/2020-4/:splat

When I try to run server I get the error:

Error: unspported redirect to value "/docs/pyrosim/2020-4/:splat" in server config; currently this must be either a remote destination or a local folder, e.g. "/blog/" or "/blog/index.html"

Is there a way to use the splat string to represent the asterisk as I do in my Netlify redirects file?

No, there is not.

1 Like

Thank you, I made a new feature request for it.

That :splat is a Netlify specific command. It’s probably better to go away from that and make the proposal about a proper redirect command that is able to redirect (.*) by using $1 like the Apache config has.

Maybe that here will help you: I have a repo where I create redirect files for Netlify via Hugo posttype.

This will not create single redirect command, but you could use it to create redirects for every single post.

" It’s probably better to go away from that and make the proposal about a proper redirect command that is able to redirect (.*) by using $1 like the Apache config has."

This is a fine idea, I don’t really care much about the syntax, I really just want the same or similar functionality in the redirects feature.

I’ll check out your repo in the meantime, thank you for the link.

My 50 cents about this:

  • I added a basic redirect feature similar to Netlify to get URL rewrites to support SPA like situations.
  • I don’t know the use case for :splat is, but if we would add something like that it would need to be really simple (since it seems that it’s me ho will have to maintain it (and possibly implement it))

The simple use case for me is to capture the portion of the URL from the asterisk to the end and append that to the end of the “to” URL. I don’t need anything else. I need to rewrite the beginning part of the URL before the * and don’t require multiple placeholders, RegEx, etc…

I understand the technical use case, what do you need this for in a “Hugo static site” context?

In my case, I have a documentation website, where we update the redirects in Netlify for ‘latest’ to point to a specific version (path) of the URL.

Example:
http://localhost:1313/docs/pyrosim/latest/user-manual/
would point to:
http://localhost:1313/docs/pyrosim/2020-4/user-manual/

In my Netlify _redirects file I have the following two lines to handle this.

/docs/pyrosim/latest/*  /docs/pyrosim/2020-4/:splat 302
/docs/pathfinder/latest/*  /docs/pathfinder/2020-4/:splat 302

You can test it here… https://support.thunderheadeng.com/docs/pyrosim/latest/user-manual/

When we release the next version of our documentation, we update this file to the new version number. Some of our other ‘tutorials’ and ‘training’ resources point to the ‘latest’ URL. We want to be able to check for broken links and click through the site when running the Hugo server and have it work the same as on Netlify.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.