Deploy previews on Netlify are built with the wrong baseURL (not using $DEPLOY_PRIME_URL)


I’m using the following netlify.toml file in my project:

The production site is ok. URLs are using the baseurl I set in the config.toml.
But the preview builds are also using this baseurl (they shoud use the $DEPLOY_PRIME_URL URL instead). So when I go on a preview build (ex:, the CSS file used is instead of

How can I fix that?

It’s difficult to pinpoint the problem without a repo to reproduce the issue. I have been using DEPLOY_PRIME_URL for both branch and preview deploys on Netlify and they work fine.

ok… Here is the repo:

Looking at the source code:

    {{ "<!-- combined, minified CSS -->" | safeHTML }}
    <link href="{{ .Site.BaseURL }}css/style.css" rel="stylesheet"{{ if not .Site.Params.disable_sri }} integrity="{{}}" crossorigin="anonymous"{{ end }}>

It’s not the best practice to manually concat the BaseURL like that, because that expects your BaseURL string value to always end in / (which is not the case if you are using the $DEPLOY_PRIME_URL directly).

Instead do: href="{{ "css/style.css" | relURL }}" or href="{{ "css/style.css" | absURL }}".

Related – I use this wrapper shell script to add trailing slash to the $DEPLOY_PRIME_URL, just because I am OCD about having the BaseURL always end with a slash.

Thank you, I fixed this. But I still have the wrong baseURL everywhere (preview deploy on Netlify):

Netlify doesn’t support using variables values ($VARIABLE) in the netlify.toml file so this is not supported:

command = "hugo --buildDrafts --buildFuture --baseURL $DEPLOY_PRIME_URL"

In their reference they suggest an alternative workflow:

1 Like

So the netlify.toml exemple on Host on Netlify ( is wrong, isn’t it?

The same for the netlify.toml of the Docs section of ?

Is someone have a working exemple?

That’s odd. I’m just referring to what I read in Netlify’s docs. Maybe their documentation is outdated and it works somehow, or hugo is using some kind of workaround like the one suggested in the docs, idk.

What works for me is having my own gulp build script (you can use something else, I’m using gulp for other things too) where I set the appropriate hugo flags based on Netlify environment variables. This way, the build command is the same for every context.

1 Like

I had the same problem with the links

I add this in Netlify.toml


publish = "public"

command = "hugo --minify --baseURL $DEPLOY_PRIME_URL"

And it work