baseURL for deployment messing up links to /static/

When I build my site locally using “hugo serve”, everything is great.

When I deploy to gitlab, using hugo --baseURL="" in the .gitlab-ci.yml deployment script (Gitlab and Hugo), then all the images referenced in the /static/ folder don’t load properly. And if I try any other basURL argument, then the navigation to the content doesn’t work. How do I work around this?

It would help if we had a bit more info per Requesting Help.

That said, have you tried --baseURL="http://username... specifying the protocol?

Sorry for not providing more detail. You can see my project here:

And you can see the site that isn’t building quite right here:

On this page in particular, there are supposed to be two images that aren’t showing up:


In response to suggestion regarding protocol, it looks like I was including http://; just did not type question correctly here. Another reason better to link to source…

The image is hosted here:

… but you have it pathed here on that page (looking at html source):

Ok, looks like images is right under static which I think is typical, but you’re copying the site up into /TradingSite? That’s where that extra URL path is coming from… I think.

I have changed the deployment file to say hugo --baseURL=""; you should be able to see this in the repository now. It does not appear to have changed anything though…

Actually now, when you hit the “Home” button on the page, it tries to go to which returns a 404 error…

Ok, looks like you may need:


… if you’re actually copying the site up into that folder? It’s acting as the site’s root, so.

Updated to your suggestion. Seems to be right back to the initial problem…

If by that you mean the images not showing, you need to set the short codes to have the right path. You were specifying /images but there is nothing there. Instead, try & specify /TradingSite/images when you set their path.

I️ will give that a try. I️m confused about what baseURL Is used for then. I️ thought the links in the shortcode would automatically have baseURL prepended to them.

Ok updating the short codes works. However the same issue seems to be affecting some aspect of the CSS rendering. Do you have any suggestions on where it look for this?

Now, after fixing the shortcodes, running into issue for css stylesheet. view-source:

Stylesheet link is href="/css/main.css"

How can I alter this to say 'href="/TradingSite/css/main.css"?

Perhaps some use ref or relref?

Looks like you found it. Your header partial refers to a css partial which uses params in the config. However, there are no params set to this, so doing what you did makes sense.

Use the absURL or relURL template funcs.

1 Like

Thank you @bep and @RickCogley.

I have been able to use relURL to avoid having to hard code /TradingSite/ by doing the following:

  • I created two custom shortcodes:
    <img src = "{{ .Get "src" | relURL}}" alt="">
    <a href="{{ .Get "href" | relURL}}" download="{{ .Get "download" }}">{{ .Get "text" }}</a>

These shortcodes can then be used in content creation without having to think about what the baseURL for the site is.

  • Similarly, I updated the partials/css section to also refer to relURL:
    <link rel="stylesheet" href= {{ "/css/main.css" | relURL }}>

This now works equally well when deployed on development server (baseURL = "") or when pushing to some other baseurl (eg, baseURL = "").

Thank you all for your help.