Rewrite index.langhere.html

1. The problem I’m having:

i have index.en.html and index.fr.html

in /
and in /foo/
and in /foo/baz/

want to serve correct file based on users language specified by browser, when they visit / or foo/ or foo/baz/

2. Error messages and/or full log output:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

3. Caddy version:

4. How I installed and ran Caddy:

a. System environment:

b. Command:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

c. Service/unit/compose file:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

d. My complete Caddy config:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

5. Links to relevant resources:

i read Content Negotiation - #2 by Whitestrake and did not understand how to achieve what i wanted

for now i have config posted in previous topic, it has no rewrite

hope you can assist with a working example

thank you very much

Howdy @gryL24!

I should point out that that thread concerns Caddy v1 and none of the configuration in that thread will be applicable to Caddy v2.

Could you do us a favour and post your current config here in this thread as well, just so it’s all in one place for us to have a look at and provide advice?

Generally, you’ll want to write a named matcher (see: https://caddyserver.com/docs/caddyfile/matchers#named-matchers) that matches a Header value (Accept-Language) and a set of paths (/, /foo/, and /foo/baz/). When you get a de in the Accept-Language you can rewrite (rewrite (Caddyfile directive) — Caddy Documentation) to your language-specific index file. (Or maybe you want de to be the default and rewrite to en when found.)

1 Like