Error sign in or login out with WPML

If your website uses nginx and the URL format for WPML is set to directory type, i.e. /en/ /en/ /fr/, you may see a 404 error when you try to access a login or registration page and when logging out in a secondary language.

To avoid this, you will need to adjust some settings on your server.

As you know, nginx has many advantages but its great disadvantage is the configuration, something more tedious. The rules for translating the login and registration pages are usually stored in the htaccess file. Because ngnix does not access this file, you will need to modify the nginx settings to add the following rewrite rules. If you do not have the permissions to do so, contact your hosting provider, and if you do not know how to do it, keep reading because I explain it to you.

The rule to add is:

rewrite ^/xx/wp-login.php /wp-login.php break;

Where xx is the language code.

If we have for example as alternative languages English, German and French should be the rule of nginx like this:

rewrite ^/en/wp-login.php /wp-login.php break;
rewrite ^/de/wp-login.php /wp-login.php break;
rewrite ^/fr/wp-login.php /wp-login.php break;

If the URL format you have configured in WPML is domain or parameter, no additional configuration is necessary.

Let’s see where to insert the code.

We will perform the process by connecting via SSH to the server. The configuration file is typically located in one of these paths:

cd /etc/nginx/
o
cd /etc/nginx/conf.d/

In the first path the file would be nginx.conf and in the second path the name depends on your settings but ends in “.conf” as well. To show the files that are in the second path we will use the command “ls”.

We edit the file with the editor:

*Remember that to edit the file you have to be in “INSERT” mode to do this click on the letter “i”.

vim ejemplo.conf

We add the rules right inside “server”. Let’s look at a partial example of the file:

server {

  # WPML
  rewrite ^/de/wp-login.php /wp-login.php break;
  rewrite ^/es/wp-login.php /wp-login.php break;
  rewrite ^/ir/wp-login.php /wp-login.php break;

  # a partir de aquí habrán más cosas

To save the file and exit, we will press the “ESC” key then “:w” to save and finally “:q” to exit.

After this it is advisable to check the nginx syntax to see that there is no error.

nginx -t

If there are no errors we will see a message like this:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Then we can recharge nginx to load the new configuration.

nginx -s reload

With that we would have it solved. I hope it helped you.

Relacionados

Adrián Pajares
Adrián Pajares

Soy Adrián Pajares, especialista en desarrollo web, y ayudo a empresas a impulsar su negocio online y conseguir más clientes.

OFERTA:
TU WEB
POR 249€

-30%

días
horas
minutos
segundos

PRECIO ANTERIOR 349€

Empezar chat
Hola,
¿En qué puedo ayudarte?