WordPress auto language detection with nginx
My blog uses the “Stella plugin free” wordpress plugin. Unfortunately this plugin doesn’t support auto language detection in the free version. But nginx has a plugin for language detection which can do the job as well. This is my sample configuration which works fine.
server {
listen 80;
listen [::]:80;
server_name hellmi.de www6.hellmi.de www.hellmi.de;
set_from_accept_language $lang en de;
location / {
rewrite ^/(.*) /$lang/$1;
}
location = /en {
rewrite ^ /en/;
}
location /en/ {
rewrite ^/en/(.*) https://www.hellmi.de/en/$1 permanent;
}
location = /de {
rewrite ^ /de/;
}
location /de/ {
rewrite ^/de/(.*) https://www.hellmi.de/$1 permanent;
}
}
The nginx module can be found here: nginx_accept_language_module