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.

2 Likes

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