Some multi language plugins like Polylang or WPML can redirect the visitor to the  homepage in the language according to his browser preferences. Unfortunately these plugins usually are using PHP for this redirection, which won’t work when the page is cached.

For this we provide some redirection examples what you can use to redirect visitors even if page is cached.

Apache/Litespeed

If you are using webserver which supports htaccess you can add the following code to General » Tweaks » Extra htaccess

RewriteEngine On
RewriteCond %{HTTP:Accept-Language} ^it [NC]
RewriteRule ^$ https://%{HTTP_HOST}/it/ [L,R=302]

RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteRule ^$ https://%{HTTP_HOST}/de/ [L,R=302]

Nginx

If you are using Nginx, you will need to add the following rules to Nginx config:

map $http_accept_language $redirect_lang {
	default https://www.example.com/;
	~it https://www.example.com/it/;
	~de https://www.example.com/de/;
}

location ~ ^/$ {
	return 302 $redirect_lang;
}