I recently set up Hugo, and have my BaseURL config set to http://www.mysite.com
On every page and post, the output of .Site.BaseURL is correctly http://www.mysite.com
However, using the default 404 page, which includes the same partial header and footer as the rest of my site, .Site.BaseURL returns the current URL of the 404’d page. Rather than a BaseURL it performs more like permalink.
So if a user went to http://www.mysite.com/abcd which doesn’t exist, and my header has a “Home” button that links to .Site.BaseURL (which correctly takes users to the homepage on every other page), the user would see just my 404 page again. They cannot navigate back home. The href to BaseURL simply links to the same erroneous page they are already on.
How can I avert this? If I set the configuration for my BaseURL to http://www.mysite.com/ with an ending slash, everything “works” – but going from 404 to the homepage results in sending users to http://www.mysite.com// (note the additional trailing slash).
Graphically this appears successful, but the additional slash is not correct. What am I missing here?
This is really perplexing to me, because it returns the current URL only for the home link. But for others (about, contact, etc) it returns just the base URL as desired. I would think if there was an issue with the variable, those additional links would be malformed as well. But they are not ¯\_(ツ)_/¯
For others who may search this, I fixed the problem on my site by ensuring my BaseURL did not have a closing slash, and using <a href="{{ .Site.BaseURL }}/">Home</a> for that link.
But on further investigation, there still appears to be something inherently wrong with /404.html being considered the same as .Site.BaseURL