Skip Navigation

Resolved

Reported for: WPML Multilingual CMS 3.2.7

Resolved in: 3.3

Overview of the issue

When using languages in domains and plugins, whose output depends on a correct filtering of the home_url() function, substituting the right language version of your site’s home url in links, links can be displayed incorrectly. In most cases this means, that the default language version of your domain is used in links instead of the correct secondary language version of it.

Another common example of this issue manifesting itself are Yoast WP SEO sitemaps not being properly displayed in secondary languages and instead showing a mere white page.

The issue itself is not caused by the WPML plugin but a difference between the Apache and Nginx webserver. The Apache webserver populates the superglobal variable $_SERVER['SERVER_NAME'] with the host requested by browsers. Nginx does not do this by default, but can be configured to do so too.

In order to do this the above workaround simply uses the variable $host provided by the Nginx webserver and passes it on to the PHP-FPM daemon handling your .php files via the fastgi_param call shown above.

The PHP-FPM daemon can then use this variable via the $_SERVER superglobal and the setup mimics the default behavior of the more common Apache + PHP(cgi) setup.

Workaround

Find the section that describes the way .php files are handled in your site’s nginx config file.
It will look similar to the below example, containing a location statement as well as the .php file ending.

location ~ [^/].php(/|$) {
        fastcgi_split_path_info ^(.+?.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }
        fastcgi_pass php;
        fastcgi_keep_conn on;
        fastcgi_index index.php;
    }

Add the line

fastcgi_param SERVER_NAME $host;

to it and by that enable the SERVER_NAME index in your $_SERVER superglobal variable, like this:

location ~ [^/].php(/|$) {
        fastcgi_split_path_info ^(.+?.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }
        fastcgi_pass php;
        fastcgi_keep_conn on;
        fastcgi_param SERVER_NAME $host;
        fastcgi_index index.php;
    }

This will cause the home_url() filtering to work exactly as on an Apache setup resolving differences in behavior and issues caused by using Nginx.