Wordpress, Redirects and WPML Wordpress, Redirects and WPML wordpress wordpress

Wordpress, Redirects and WPML


An alternate way to approach this:

Listen to your customer's browser setting.

locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']);

https://secure.php.net/manual/en/locale.acceptfromhttp.php

You can then rewrite it to a function like this:

function my_get_langauge() {    static $lang;    if(is_null($lang)) {        $lang = strtolower(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2));        /**         * Check list of allowed/accepted languages or revert to default         */        if(!in_array($lang, ['nl','en','de','it']) )        {            $lang = 'en';        }    }    return $lang;}

This way you don't have to worry about redirects for languages, and you can accept languages as your website user wants to see it.


If you test your expression online you'll see that your regex is removing the first-asset part of the URL.

Regular Expression: assets\/(.+)\/?Test String: /it/assets/first-asset/

This will return /it/assets/.