Baseurl and relativeURLs is ignored

Not sure what I am doing wrong but I still get localhost instead of the URL I configured.

config.toml has:

baseurl = "http://pasaule.dodies.lv" relativeURLs = true canonifyURLs = true

and this command confirms it:

Normundss-iMac:Sites normis$ hugo config | grep url baseurl = "http://pasaule.dodies.lv/" canonifyurls = true relativeurls = true uglyurls = false

but the hugo server command still generates localhost:1313 in all the links:

<li>
<a href="{{ .Permalink }}">{{ .Title }}</a>
</li>

becomes

<li>
<a href="http://localhost:1313/celojumi/2015-usa/01/">Prologs</a>
</li>

and same happens with my CSS files:

<link rel="stylesheet" type="text/css" href="{{ .Site.BaseURL }}css/pixyll.css">

becomes

<link rel="stylesheet" type="text/css" href="http://localhost:1313/css/pixyll.css">

Do you run hugo server in watch mode (aka “dev mode”)? There are some baseURL magic going on there. @spf13 knows more.

On a side note:

relativeURLs = true
canonifyURLs = true

relativeURLs = true will override whatever is in canonifyURLs. relativeURLs is a special little setting, mainly to support having Hugo sites just sitting there on the file system with no web server.

1 Like

Yes, I do use -w mode, I also restarted it. I removed canonifyURLs but there is no difference.

I am testing the page on my local machine, and then Rsyncing it to the webserver, but as you see, there are hardcoded “localhost” links in the Rsynced version, which is why I am asking the question **how to get rid of them ** thanks :slight_smile:

EDIT: SOLVED. yes, the “-w” mode causes the problem. Removed this flag and generated URLs correctly. Thanks

I found a workaround by using this in my links:

<a href="{{ .RelPermalink }}">{{ .Title }}</a>

I think I just read this somewhere else. It was a big revelation for me! So now I know to always run hugo without any switches as a last step just before final git add/commit/push steps.

1 Like

I would recommend to separate your dev and prod builds (there is a flag for that).

Me, I have

/dev
/public

I seem to have a similar problem. I’m running Hugo 0.16, and I can’t get relativeURLs working at all.

In my config.toml:

baseurl = "http://example.com/"
languageCode = "en-us"
title = "Summer Blog Project"
theme = "sbp-strata"
relativeURLs = true

Then I run:

hugo server --bind 0.0.0.0 --port 8000 --log --logFile port8000.log

And it serves all of my content with localhost URLs.

This:

<script src="{{ .Site.BaseURL }}js/jquery.min.js"></script>

Gets served out as:

<script src="http://localhost:8000/js/jquery.min.js"></script>

Which, since I’m running Hugo on a VPS and a browser on my laptop, means all of the links and includes don’t work.