Multiple error pages for multilanguage sites

Hi guys,

trying out caddy, I am happy to have found a Go product which fits most of our needs.

Just one thing so far which I could not figure out:

I need localized “404 Not found” pages, so “/en/some/path/not/existing” should diplsay /en/not_found.html", whereas “/fr/some/path/not/existing” should diplsay /fr/not_found.html".

In one issue responds, use of “rewrite” is suggested, but I dont get it. How can I rewrite non existing paths?

Anyway, help or fix would be appreciated.

Best
Martin

Hi @martinrode, welcome to the Caddy community!

The errors directive doesn’t have a method to specify locale-specific error pages, and as you noted it is a bit difficult to rewrite a nonexistent path - but that doesn’t mean it can’t be done.

Since your locales appear to be prepended to the URI, you can use multiple site definitions to achieve what you want. Try something like this example:

(not_found) {
  errors {
    404 not_found.html
  }
}

example.com/en {
  root /var/www/html/en
  import errors
}

example.com/fr {
  root /var/www/html/fr
  import errors
}

(If your error pages aren’t identically named and placed, the Caddyfile snippet might not be appropriate.)

1 Like

Ok, thanks. I thought about this solution, but it is a lot of config, considering that we have multiple domains with multiple languages each.

So, may be you could improve this in a future version? Would be great!

The auto-https feature is for sure what sold us to Caddy.

I don’t think there’s any reason the errors directive couldn’t be altered in this way.

Could you jump over to https://github.com/mholt/caddy/issues and open an issue for this feature request? Let us know if there’s any specifics you’d like to see, and the contributors can discuss possible implementation.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.