baseURL is passed as a command line option here and it works perfectly:
hugo --baseURL "${{ steps.pages.outputs.base_url }}/"
The problem is that I’d like to be the same on both sites. So that the GitHub Pages site also refers to the original domain name. I’m interested in your advice on how to achieve this simply.
currently you have two deployments with different domain names hosted by different servers. And you want your site to be available using both domain names and these sites are identical
You will have to publish the site only once and let’s say “redirect” the site from one server to the other.
As far as I know, you cannot redirect a Github Pages site to a custom server. But the other way round is possible, if your domain hosting sevice supports it.
So the solution would be:
publish your site to github pages https://username.github.io/repo
redirect your custom domain www.my-domain.com to the one above. (usually using a verified CNAME)
That way regardless of the used URL when accessing the site:
https://username.github.io/repo
https://www.my-domain.com
it will be always shown as: https://www.my-domain.com
Here’s a link to the official documentation:
There are a couple of tutorials around search for “github pages custom domain name”
Yes, these 2 sites are identical. And I would like to be able to access one or the other. This is already the case and it’s perfect.
No, I want to publish this site twice. And I don’t want any redirects. The idea is that the GitHub Pages version remains completely accessible if my domain name or my hosting disappears.
What I don’t want is a referencing of the site, which is hosted on GitHub Pages. And I think canonical is more elegant (and more correct) than blocking with noindex or a robots.txt file.
NB 1: The noindex solution is trivial:
{{ if not (hasPrefix .Permalink "https://nicolasfriedli.ch/") }}
<meta name="robots" content="noindex">
{{ end }}
NB2: I think we need to do something like (pseudocode):
This matter isn’t actually that complicated. I’ve set baseURL = "https://a.com/" in hugo.toml and deployed the website simultaneously on Vercel, Cloudflare Pages, and my own VPS, using a.com, b.com, and c.com respectively.
In daily use, the latter two don’t seem much different, except that a few fixed links actually point to resources on a.com. If a.com unfortunately goes down, I can just manually change the baseURL.
Having multiple domain names for the same website content doesn’t really serve much purpose anyway.