Content Negotiation

Hi @georg.cachinger,

Both the rewrite and redir directives support conditional operators based on request headers (in the format {>Header}.

For example, assuming:

  • Your English site is located under /en
  • Your German site is located under /de
  • You want to serve English as a default
  • You don’t want the URL to change by locale

You might structure a rewrite-based solution like this:

example.com
rewrite {
  if {path} not_starts_with /de
  if {path} not_starts_with /en
  if {>Accept-Language} is de
  to /de{uri}
}
rewrite {
  if {path} not_starts_with /de
  if {path} not_starts_with /en
  to /en{uri}
}

A redir solution would be quite similar, the major difference being exposing the localisation prefix to the user in their URL bars.

https://caddyserver.com/docs/rewrite
https://caddyserver.com/docs/redir
https://caddyserver.com/docs/placeholders