baseURL with path lead to wrong paths generation


I have the following config for my test site:
There is a key: baseURL = “”. You can go by this url and see that this leads to the state when many links broken and theme doesn’t work after generation.

The reason is that baseURL have path “hugo-test/” which is truncated during generation.

The same is happening when I generate site locally and set as baseURL not just “localhost”, but “localhost/some/path/”.

I’ve read on this forum that "absURL does prepend the baseURL if you pass in a path starting with / , but it removes any path in the baseURL before doing so."

Why? What is the purpose of baseURL? What is the correct way to make things work?


So I cloned your repo and took a look. As is, yes it looks broken. For the stylesheets though, all I did was remove the / at the beginning and then the site works locally just fine.

Don’t use a leading forward slash if you’re going to format your URLs with absURL or relURL.


I did the same with your category links and they work as well. Leave baseURL as it is, both locally and for production, you don’t need to touch it. Then remove leading forward slashes from your links.

1 Like

Thank you for help.

As far as I understand your advice I should change every related URL in theme which starts with “/”.
I see only one approach to find related URLs. It’s “grep absURL . -r” in project directory. It should give me raws with related URLs since absURL is a method which performs related URL transformation. Is it correct?

But!.. my theme is hugo-x, it is among other legitimate Hugo themes from I expect it to work out of the box. It seems a little bit peculiar that user needs to edit theme source code.

I think your case is special because of your baseURL value, hence the leading /s are giving issues.

Themes on the Hugo theme website are built against an example site. If that works, then they are okay to be added. Those themes don’t get an in-depth review.

The theme developer didn’t build that theme with the use case of someone hosting their site via a sub-directory, which is what you’re doing. Instead of making the changes in you’re repo, you can open a pull request for that theme and make the changes there. This way anyone who uses that theme will benefit.

1 Like

Thank you very much. I see now.

1 Like

First: I do like Hugo very much. The work done by the team is great.

But I keep reading that, by design, ‘baseURL’ can not have a subdirectory path because absURL and relURL just compute the path relative to the domain name, without the path.
I think it is of great value to use relative path’s, from the baseURL.
That way, a site is portable over subdirectores (often used for testing).
Now, the subdirectory path is repeated:
baseURL: “
relURL of ‘/subdir1’ results in

I hope nobody will agree that this is a useful design.
Since it renders the ‘feature’ useless, it does not harm to fix the problem.

Thanks guys