Nginx + Wordpress language redirect wrong with default language
Sorry for duplicate this questions here:
Nginx + Wordpress language redirect
All works but for the default EN language.
I just want to redirect JP visitors to /ja/ directory, maybe more other countries to other directories later.
For now, I want all other countries to the root domain.
The rule I used is:
map $http_accept_language $lang {
default en;
~ja ja;
}
...
rewrite ^/$ /$lang/ permanent;
This rule redirected all other visitors to mydomain.com/en/, that's 404 of course since EN is my main language!
=======================================
This is all the rules in the site side config
Hope anyone can help me with this !
map $http_accept_language $lang {
default en;
~ja ja;
}
server
{
listen 80;
listen 443 ssl http2;
server_name mydomain.com www.mydomain.com;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/mydomain.com;
#REWRITE-START
rewrite ^/$ /$lang/ permanent;
include /www/server/panel/vhost/rewrite/mydomain.com.conf;
#REWRITE-END
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
location ~ \.well-known{
allow all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log /dev/null;
access_log /dev/null;
}
location ~ .*\.(js|css)?$
{
expires 12h;
error_log /dev/null;
access_log /dev/null;
}
access_log /www/wwwlogs/mydomain.com.log;
error_log /www/wwwlogs/mydomain.com.log;
}