Hugo alias and parameters

Hello,

I have a hugo url as follows /en/id/verify-email?code=TOKEN

The verify-email.html file as an alias
/id/verify-email

However when I get a request in for /id/verify-email?code=TOKEN this needs to redirect to /en/id/verify-email?code=TOKEN but the params are being stripped off on the redirect

Is there anyway in Hugo to handle this?

Thanks in advance
Gearoiud

You need to write your own alias template.

Thanks for the reply @bep - I will digg into this more so, BUT may be back :slight_smile:

Hi @bep I have a custom alias template but not sure how to grab the parameters code and its value token? so I can do the redirect with them in the URL.

This might be helpful:
https://discourse.gohugo.io/t/preserve-the-some-anchor/37413/2

1 Like

Thanks, thats a bit more elegant than what I came up with

<!DOCTYPE html>
<html>
  <head>
    <title>{{ .Permalink }}</title>
    <link rel="canonical" href="{{ .Permalink }}">
    <meta name="robots" content="noindex">
    <meta charset="utf-8" />
    <meta http-equiv="refresh" content="0; url={{ .Permalink }}" id="meta-tag" />
  </head>
  <script type="text/javascript">
    var url = document.querySelector('meta[id="meta-tag"]').getAttribute("content");
    document.querySelector('meta[id="meta-tag"]').setAttribute("content", url + window.location.search);
  </script>"
</html>
2 Likes

Really appreciate your help @bep :+1:

1 Like

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