What is the correct thing to do instead of relativeURLs = true?

I am new to Hugo, having recently started work on a project that uses Hugo for its documentation website. I’m trying to fix a problem with the links Hugo generates. The documentation needs to be accessible from different paths depending on the domain. For example, the docs should be accessible through either https://www2.cs.duke.edu/donaldlab/software/osprey/docs/index.html or https://donaldlab.cs.duke.edu/software/osprey/docs/index.html (note the latter doesn’t have /donaldlab/ in the path). Our baseURL is currently https://www2.cs.duke.edu/donaldlab/software/osprey/docs/, so Hugo generates links that look like /donaldlab/software/osprey/docs/research/. These links work through www2.cs.duke.edu, but not through donaldlab.cs.duke.edu, because the latter doesn’t have /donaldlab/ in the path. If Hugo generated the link as research/, for example, then it should work either way. In addition to hyperlinks, CSS references are broken for the same reason when accessing through donaldlab.cs.duke.edu.

Setting the option relativeURLs = true seems like exactly what we need, but I see that the page URL management | Hugo warns me that I should not do this unless I’m creating a serverless site. But if not relativeURLs, what is the correct way to achieve the same thing?

Project link: https://github.com/donaldlab/OSPREY3

Output of “hugo env”:

hugo v0.122.0-b9a03bd59d5f71a529acb3e33f995e0ef332b3aa linux/amd64 BuildDate=2024-01-26T15:54:24Z VendorInfo=gohugoio
GOOS="linux"
GOARCH="amd64"
GOVERSION="go1.21.6"

Thank you for your help!
-Allen

This was discussed recently: Invalid image links in 0.123 for baseURL with subdirectory

Thanks. I saw that thread, but the only conclusion I could glean was that relativeURLs is only intended for serverless sites, not for my use case. But I still don’t know what the correct solution for my situation is; I just know that it isn’t relativeURLs.