"Too many redirects" error due to conditionals?

Hey folks,

I’ve been using Hugo for my website for many years now with almost no issues. I love how fast Hugo is, and how painless upgrades have been. I just wanted to start off with that to say thank you to Hugo team for all your great work!

I encountered a very strange & unexpected issue recently, and was hoping to get some help on it. The issue is regarding this page specifically on my site: https://salman.io/about/. The way I’m serving this page is that it’s a simple Markdown file in the root directory, with type: page. Nothing complex about it! There are many pages like that. However, the one thing about this page which is different than others (e.g. /books or /work) is that I don’t want the title to show up at the top (e.g. “About”). So, I didn’t specify a title attribute. But then I noticed the actual html document title was not set… so I decided to set the title, and add this line of code to the layouts/_default/single.html:

{{- if (not (eq .RelPermalink "/about/")) -}}
  <h1 class="title">{{ .Title }}</h1>
{{- end -}}

This basically ensures that I can specify the title in the front matter for about.md, it will be used in the main html title, but it will not actually render this h1. All of this works fine, I deployed and it worked fine.

Then, one day, someone told me that when they try to access “salman.io/about” in Chrome, it fails with a “too many redirects” error. I was able to reproduce this myself on production (never happens locally), only in Incognito mode, and only in Chrome. It doesn’t happen for other browsers.

I was really at a loss, and the only thing I could think of was reverting the conditional check. I figured maybe somehow it’s redirecting and then checking that logic, etc… And so once I reverted, the issue was resolved.

It seems as though something about that conditional causes redirect errors in the particular scenario I have. Have you seen anything else like this? Alternatively, is there a better way to achieve what I’m trying to do, which is modify the base template to conditionally show things? I suppose I could check some variable inside the front matter, but I worry that will still be a conditional check and am wary of doing so.

Thanks in advance for any help!

No, it does not.

I visited your site using Chrome (incognito mode) and was unable to reproduce the reported behavior.

Thanks for your response. Just to clarify from my post (sorry, I know it’s long), the issue was happening for me only on production when I had that conditional enabled. I then reverted the change and re-deployed and the issue was gone. So you cannot currently repro the issue using my website.

I was hoping someone might have a sense of the issue based on the conditional logic.

I suppose the most helpful would be to create a separate example site demonstrating the issue?


1 Like