Initial redirect from base URL to "en" localized subdirectory

Hi, I am not very experienced with Hugo, and I set up a site you can see the source here

and deployed here (for now)

It’s using Hugo v. 0.27.

My problem is this: when I access the base URL for the site given above, I get redirected to the same URL but with a trailing “/en/”. Probably the Theme does this for me since it’s the default language of the site.

While this is usually not a problem, when trying out Netlify’s awesome “Preview Deploys”, I find I can’t use them because the redirect uses the baseURL variable and so a preview deploy here


will get redirected to the main deployed site:

instead of the alternative version, which should be:


I tried reading up on Hugo’s Content Management in help, but it doesn’t really say where and how Hugo looks for the initial document to show at the root of the site.

So I come here asking for help:

  • understanding better what Hugo is doing to set up my main “public/index.html”, so I can find the place in the source where I need to fix this

  • what is the best way to fix this so that I can use Netlify’s Preview Deploys, which seem to generate random id’s for the URL’s in each deploy

Thanks in advance for any help!


defaultContentLanguageInSubDir: false

In config.

As to the previews, this is discussed in a recent thread. You need to somehow set the correct baseURL – lots of stuff might behave oddly without it.

The defaultContentLanguageInSubDir: false did the trick - no more redirect when entering the main URL. Good!

So, if I understand correctly, this content of my public/index.html:

<!DOCTYPE html><html>
<link rel="canonical" href=""/>
<meta name="robots" content="noindex"><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="0; url=" />

… this is not coming from any file in my source, this is built by the Hugo engine based only in my preferences (like those settings in config.toml), is this correct?

About the deploys - which I can now use pretty well, at least I didn’t run into any problems yet - it would be nice if Hugo was completely URL-agnostic, if it was able to pick up the URL from some browser hack, instead of needing a variable set.

With the automatic deployments people do these days, this would be a great feature. But I have no idea if it’s too complicated, or even possible.

Thanks a lot for Hugo (I am VERY impressed), thanks a lot for this answer.

Hugo is a static site generator. URLs are the CORE thing we do. We will never be URL-agnostic. You should ask Netlify support about how to set HUGO_BASEURL env correctly for the deployment previews.

1 Like

Ok, I see, I will ask Netlify about it.

Thanks for the lesson, I am still wrapping my head around this static-site thing. Basically it means Hugo is “not there” when the site is deployed and running, its work is finished long before that.

But I would say you are very near to what I meant when I wrote my “URL-agnostic” ignorant comment, in the sense that using relative URLs will probably solve 99% of the issues.

Thanks for you work and for you help here. See you around!

You are right about that. It’s that fact that actually makes the Hugo Docs Pull Requests actually look just fine. I haven’t invested time in the whole baseURL vs Netlify vs PR branches.

See hugoDocs/netlify.toml at master · gohugoio/hugoDocs · GitHub

1 Like