We want to change defaultContentLanguageInSubdir to true. It wasn’t set before. The consequence is, that /places is now /en/places. But we still want to support the old path. Actually we want to write a alias.html file with some JavaScript, that detects the current browser’s language and redirects to it.
Since v0.155.0, it’s not possible to define aliases from root anymore.
We basically want to do, what @jmooring describes in this issue, but we don’t have an apache, but instead want hugo to render the alias.html for all currently existing paths, so the redirect redirects to the browser’s language.
So we have for example
/en/places
/de/places
/fr/places
and we want to have a /places that redirects to one of those pages (the one of the browser’s language or /en/places as fallback).
It’s done as a service by KDE. I don’t know what they use. We provide the static files and they host the static files. So we need static redirect html files generated by hugo with the alias.html template or something similar.
Here is the change I tried. Besides the pipeline not building, I realized that the old aliases are removed. Would be happy to find a working solution.
Run an experiment. Create an .htaccess file in your static dir that redirects /foo to a valid page and see what happens. Presuming you get a small experiment to work, then you can get creative with language detection…
RewriteEngine On
RewriteBase /
# Skip language redirects for the css and js folders, or png and ico files in the root
RewriteRule ^(css/|js/|[^/]+\.png$|[^/]+\.ico$) - [L]
# Do nothing if the url already starts with one of the supported language codes
RewriteRule ^(en|de|fr)(/|$) - [L]
# Redirect to the german section if the browser's first language is german
RewriteCond %{HTTP:Accept-Language} ^de([-|_|;]|,|$) [NC]
RewriteRule ^(.*)$ /de/$1 [R=302,L]
# Redirect to the french section if the browser's first language is french
RewriteCond %{HTTP:Accept-Language} ^fr([-|_|;]|,|$) [NC]
RewriteRule ^(.*)$ /fr/$1 [R=302,L]
# Fall back to the english section for all other visitors
RewriteRule ^(.*)$ /en/$1 [R=302,L]