I have a cloudfront distribution serving an s3 bucket. To make the page multilanguage, I added a lamba@edge function that analyzes the Accept-Language header and redirects /<page>
to /en/<page>
or /de/<page>
.
The redirect happens with a 303 return code so that the users gets /en/<page>
as the path shown in the browser and can switch languages by going to /de/<page>
.
Works! But what is in case of a 404? If I configure a custom 404 page in S3 or cloudfront and the user requests /de/<non-existing-page>
, he gets redirected to the custom 404 page (for example /error-pages/404
). But that page is not translated!
Is there a way to make the 404 page language specific? Depending on if the user comes from /en/<page>
or /de/<page>
?
I found a solution.
ErrorDocument
for each bucket to the language-specific 404 pagePathPattern
/<language>/*
is directed to the origin fetching from the s3 bucket for language <language>