[Remove Large Media] Hugo Multilingual Multihost

I’m considering using different baseURL for the different languages I have my site in, built with Wowchemy (which uses Hugo). I’m reading this but have some questions, especially regarding the setup of the different domains in Netlify and the redirects. For example, my current English site is here but I want it to be here (https://physichemically.com) (keeping my multilingual setup, so that Hugo recognizes when a page is translated). Do I need to register that domain with Netlify too? I’d also like to redirect all my links starting with /en/ to that new domain.

Thanks in advance!

You’d have to add all the domains you need Netlify to serve in your Site Settings. However, all domains redirect to the primary domain, if you need multiple domain to work independently, you’d have to create multiple websites, I suppose.

The redirects are fairly easy to achieve with a _rediects file, but I think we should fix the domain mashup first.

1 Like

Thanks a lot. If I add domain aliases then physichemically.com will redirect to fisiquimicamente.com (my primary domain), right? I’d rather use different domains for each of my languages. Since with Hugo Multihost each one of them is put in a separate folder, I guess I could create two different sites each of them deploying each folder (but sharing the same GitHub repo?

Yes, you can create two websites with the same repo and set the publish path accordingly. It should work fine.

1 Like

So I should set here:

my publish directory to public/es and/or public/en for example, depending on the language?

Also, for the redirects, since the domain wouldn’t be the same, I understand that it’s not possible to use Netlify redirects, am I correct?

Yes, you can set it up there or use netlify.toml: File-based configuration | Netlify Docs.

I’d advise you to build locally and push the public folders if possible or else you’d end up using multiple build minutes for the same website. If you build locally, Netlify would just have to publish it.

It’s possible to use _redirects regardless. In the website that you want to redirect from /en, your file can look something like:

/en/* https://www.newdomain.com/:splat 301!

1 Like

Thanks a lot @hrishikesh . I’ll try this ASAP. For the redirects, can you share with me the syntax if I use it with my netlify.toml? I remember having to set one redirect with Cloudflare since with Netlify it wasn’t working (perhaps I didn’t wait enough, although with Cloudflare it was instantaneous).

Netlify ones get activated as soon as you deploy the website, so I’m not sure why you faced the behaviour. However, the netlify.toml one could look like this:

  from = "/en/*"
  to = "https://www.foo.com/:splat"
  status = 301
  force = true
1 Like

One question remains :thinking:. If both sites share the same repo, how can I manage their different netlify.toml files?

Yes, that’s a problem. The alternative would be to use _redirects file and create the file (or copy it from somewhere) during build.

For example, you can add a _redirects file to the root of the repo. Then, in the website that you want the redirect to work, you can change your build command to hugo --minify && cp _redirects /public/. You’d have to replac public with the actual publish path of that website.

For the other website, you don’t need to copy the _redirects file, so only hugo --minify should work.

The _redirects may not be that problematic after all, as all sites can have the same rules (only in some of them they will actually be applied). The thing bothering me more is how can I substitute my current netlify.toml file with settings in the UI for each site :thinking:.

I read that the configuration file overrides settings set in the UI. Does that mean I can remove my publish directory from it and set it in the UI (one for each site deploying each language)?

Yes definitely. Only the values set in netlify.toml will take preference over the settings in UI. The rest would be directly used as is from UI.

1 Like

Hey @hrishikesh . I’ve managed to create the different sites in Netlify and set up all the domains and everything, linking all sites to the same Github repo but specifying the publish directory to each of the languages (public/es, public/en and public/ca). Now the problem comes when the original site deploys successfully and actually the multilingual part seems to be working, but the other sites do not have access to the repo so I can’t deploy them. This is what I’m getting:

2:18:43 AM: Build ready to start
2:18:45 AM: build-image version: be42e453d6c8f171cc2f654acc29c0a8b60e6d93
2:18:45 AM: build-image tag: v3.7.1
2:18:45 AM: buildbot version: 94f1b7736437a080e02c046e77c9a098022fec84
2:18:45 AM: Fetching cached dependencies
2:18:45 AM: Failed to fetch cache, continuing with build
2:18:45 AM: Starting to prepare the repo for build
2:18:45 AM: No cached dependencies found. Cloning fresh repo
2:18:45 AM: git clone https://github.com/rodrigoalcarazdelaosa/fisiquimicamente
2:19:02 AM: Error cloning repository: https://github.com/rodrigoalcarazdelaosa/fisiquimicamente
2:19:02 AM: Creating deploy upload records
2:19:03 AM: Failing build: Failed to prepare repo
2:19:03 AM: Failed during stage 'preparing repo': exit status 128
2:19:03 AM: Finished processing build request in 18.39417594s

I can show you the different site settings or anything you need. Thank you very much in advance!

Thanks to Netlify I’ve successfully redeployed a working version of my site so the online (live) site still works as before :stuck_out_tongue_winking_eye:

This might come as a bummer.

Till now, I thought one could deploy multiple websites from the same repo, but they probably can’t. I had tried doing this once, but the only difference was, the new website was created as a different branch. Probably that’s the reason why it had worked. I don’t see any other reason why the cloning is failing.

Also, I re-read the docs on domain aliases (multiple custom domains to same website) and looks like, you could have got away with this configuration under the same website. I really apologize for the confusion, but would you be willing to rework a little bit? Would it be possible for you to change the configuration to something like English as the home page and the other two languages in their sub-folders? Then what you can do is, add redirects in netlify.toml like this:

  from = https://www.foo.com/
  to = https://www.physochemically.com/
  status = 301
  force = true

  from = https://www.foo.com/en/*
  to = https://www.physichemically.com/:splat
  status = 301
  force = true

  from = https://www.physichemically.com/es/*
  to = https://www.foo.com/es/:splat
  status = 301
  force = true

  from = https://www.physichemically.com/ca/*
  to = https://www.foo.com/ca/:splat
  status = 301
  force = true

where foo.com is your other domain.

Let me know if this works out and again apologies for the double work.

Thanks for your response. I’m still trying to make it work with the previous configuration but I’m facing now a similar issue even though I’m using different repos. I’ve now created different remote repos for as suggested in the Hugo Forums but when I try to clone that new repository I still get the same error 128:

12:20:40 PM: Build ready to start
12:20:42 PM: build-image version: be42e453d6c8f171cc2f654acc29c0a8b60e6d93
12:20:42 PM: build-image tag: v3.7.1
12:20:42 PM: buildbot version: 94f1b7736437a080e02c046e77c9a098022fec84
12:20:42 PM: Fetching cached dependencies
12:20:42 PM: Failed to fetch cache, continuing with build
12:20:42 PM: Starting to prepare the repo for build
12:20:43 PM: No cached dependencies found. Cloning fresh repo
12:20:43 PM: git clone https://github.com/rodrigoalcarazdelaosa/physichemically
12:20:58 PM: Error cloning repository: https://github.com/rodrigoalcarazdelaosa/physichemically
12:20:58 PM: Creating deploy upload records
12:20:58 PM: Failing build: Failed to prepare repo
12:20:58 PM: Failed during stage 'preparing repo': exit status 128
12:20:58 PM: Finished processing build request in 15.91687361s

I’m not sure why this is happening, as apparently is just setting up a new site pulling from a different repo :thinking:

Seems like Netlify is having troubles connecting to your Git repo(s). I think a support engineer would be able to investigate this.

Meanwhile, it’s probably not the case, but would you check it Netlify app is properly installed in your GitHub account? And maybe you’ve used LFS somewhere?

Just in case this makes any difference. I’m using Netlify Large Media in my original repo/site. What I did was to set up two different remote repos for the other languages and push everything from my original repo to those other two. That means I now have (all three repos have exactly the same information):

When those sites are built, Hugo creates three different folders inside public, namely: public/es, public/en and public/ca. Now in Netlify I have three different sites that are pulling from each repo and have configured the publish directory to each of those folders (depending on the language).

Yes, as I thought, probably the LFS is causing some issue. You can try steps on this thread: Can't clone from git -error 128 but permissions etc seem ok and no webhooks setup - #4 by laura and let us know.

1 Like

So I probably need to set up Netlify LM in all sites. I’ll report back. Thanks again!