baseURL = causes wrong menu links like


I am a Hugo newbie, so apologies if the cause of the below is obvious to you, but I cannot seem to make a baseURL work if it contains more than just the domain, e.g. For some reason, the links to content contain the “test” dir twice, like e.g.

I already searched through the docs and the forum but without a result.

What I have in config.toml:

baseurl = ""

		name= "About"
		url = "/about/"

All other relevant settings should be pretty much default. (E.g. I did not set canonifyurl etc.)
And in content/ there is an file. Nothing unusual so far.

Now if I run Hugo (v0.15) to generate the site into $PUBLIC_WWW/test…

hugo -d $HOME/html/test

…and point a browser to, the home page loads fine but the link to the about page looks like this:

The theme I use is Hype-X.

Did I overlook something obvious? How can I make this setup work?


1 Like

This looks strange; you can try to add server-relative URL in the menu config “/test/about”, but other than that I would suggest you try the Hugo source version. We should really, really release a new version soon. A lot have happened since 0.15.

1 Like

Thanks for this suggestion, it made indeed a difference. Now the menus (about etc.) work fine, but the links that worked previously (like CSS links etc.) now have no test/ part at all, just as if they ignore the baseURL. (All those links, as far as I checked them, are of the form {{ "/css/poole.css" | absURL }}. Strangely enough, the menu links use the same format: {{ .URL | absURL }}. (Note this template code is from the Hyde-X templates - I assume this theme has been used and tested since quite a while now.)

This is what I observe with v0.16-DEV:

Menu links work now (from layouts/partial/sidebar.html). Their template uses this format:

{{ .URL | absURL }}

The “Home” link doesn’t work (also located in sidebar.html). The template format is similar:

{ "/" | absURL }}

CSS links fail, too (in head.html) - same template format:

{{ "/css/poole.css" | absURL }}

When I remove the leading slashes, the Home link and the CSS links start working:

{{ "" | absURL }}


{{ "css/poole.css" | absURL }}


I also noticed that image tags from the Markdown source of a blog post do not seem to get processed properly. Of the following image tags, only the last one works:

![image](gopher.png "Gopher")  <-- fails

![image](post/gopher.png "Gopher") <-- fails

![image](/post/gopher.png "Gopher") <-- fails

![image](test/post/gopher.png "Gopher") <-- fails

![image](/test/post/gopher.png "Gopher") <-- works

Because of the baseURL setting ("") I should not need to use “/test/” at all in the image path.

All of this is quite confusing. I only want to live-test on a real server without exposing the site to the public yet. With local hugo server (which ignores the baseURL) everything works like a charm.

Is there any other approach for testing a site from within a subdirectory, without breaking half of the links?


I finally found a workaround to the issue:

Use a subdomain.

It seems as long as the baseURL does not point to any subdirectory, everything works well.

The absURL function only converts relative paths. If you pass in a string that starts with http or /, absURL doesn’t prepend the baseURL. We should update the docs to explain this behavior.

The image tags in your Markdown are a bit of a special case. The blackfriday package renders that content without Hugo processing the URLs/paths. Hugo’s baseURL capabilities come into play only in the layouts. If you want to use absURL from within your content, you’ll need to create a shortcode for that. For example:

![image]({{< absurl post/gopher.png >}} "Gopher")
1 Like

After looking at the code, I need to correct my last post.

That should be: If you pass in a string that starts with http or //, absURL doesn’t prepend the baseURL. Note the double slash.

absURL does prepend the baseURL if you pass in a path starting with /, but it removes any path in the baseURL before doing so. So, instead of prepending, it prepends

I don’t know where all this function is being used inside of Hugo, but it is confusing.

In my tests the baseURL always got prepended, just not always with the correct result. If absURL ignores strings that start with /, then there must be some other mechanism that also builds a full URL from the snippets in the layouts (and fails when the baseURL points to a subdir).

Anyway, after switching from subdir to subdomain, I have not seen these problems anymore.


Don’t know, but maybe the absURL is not used in your layout, there is another way to get a full path:

<link href="{{ .Site.BaseURL }}favicon.png" rel="shortcut icon">

These different ways of creating a full path may be a reason that it is working sometimes…

Thanks for the hint, I’ll keep this in mind in case I build my own layout. Right now I use Hype-X which works fine so far. I only tweak the visual appearance a bit, that’s enough for me until I get more familar with Hugo theming.

I found this old topic when I tried to solve an issue where absURL suddenly was not working after upgrading Hugo from version 0.15 to 0.17. In v0.15 you could use / in absURL like this: href="{{ "/css/highlight/" | absURL }}default.css" but now in v0.17 I had to remove the first /: href="{{ "css/highlight/" | absURL }}default.css". to make it work.

I have not seen any documentation that it’s behaviour has changed.

Anyway good to find a solution!

1 Like