Incorect url domain prefix in build preview links

In build preview, sometimes links redirect to the master website (using the main domain instead of the test domain)

For example for this Pull-request: https://github.com/letsencrypt/website/pull/641 with preview https://deploy-preview-641–letsencrypt.netlify.com/docs/ :

  • Links on the top menu start with https://deploy-preview-641–letsencrypt.netlify.com/
  • Links in the page incorrectly start with https://letsencrypt.org

This makes the navigation in the preview difficult.

Is there something missing/wrong in the Hugo source or is it a netlify bug? (when building locally the website, all links have localhost as base)

@tdelmas, thank you for this question and welcome to our community site! :+1:

My best guess is the site markdown is using absURL and not relURL for the links.

Using absURL includes an absolute link with a domain name whereas relURL will make relative links which will be independent of the domain.

Changing the absURL links to relURL should resolve this.

If this solution doesn’t work for any reason or there are other questions about this, we are happy to answer.

1 Like

Thank you for that answer!

You’re probably right, I’ll check the code. (I hope it will be easy to fix, the code is a little complex, using full urls to handle partial translation and rewrite links)

I’ll post an update once I have more details.

1 Like

great! let us know what you find!

Of course, updating ref to relref solved the issue. Thanks again for the quick answer!

I was wondering if in the future, the netlify build could automatically update the baseURL, in the same way it’s done for local build where hugo replace it with localhost :smile:

@tdelmas, it should possible to do this automatically in the build command itself with something similar to the following:

hugo -b "$URL" 

There are also some examples here in the Hugo docs for deploy previews, to “bake in” the deploy preview URL like so (this goes in netlify.toml):

[context.deploy-preview]
command = "hugo --gc --minify --buildFuture -b $DEPLOY_PRIME_URL"

This uses a different environment variable $DEPLOY_PRIME_URL which is specific to the deploy previews.

Using these methods, it should be possible to make the URLs always specific to where they are deployed.

1 Like