Rewrite and combine query strings for wordpress

I’m working with two plugins with a different language query string setup. The language plugin itself works with mydomain.com/?lang=english (polylang plugin), the other plugin needs to retrieve mydomain.com/?language=english.

How should I rewrite the url so both are working correctly? I’ve tried the following:

Read More
   function languagerewrite() {
     //$language = get_query_var('lang', 1); 
     //get_query_var not working, yet 'lang' is registered Why? 
       if(isset($_GET["lang"])) {
       $language = $_GET["lang"];

      echo esc_url(add_query_arg( 'language', $language ));
      }
    }
    add_action('init', 'languagerewrite', 10, 0);

This will echo the following:
?lang=english&language=english which should work, although I need to rewrite that to a nice url.
How can use the printed url? And is this the best way to do this in php or should I rewrite this in htaccess? Thanks.

Related posts

1 comment

  1. Use such htaccess

    RewriteEngine on
    # two lines to avoid endless redirect. Although you may leave only 1st
    RewriteCond %{QUERY_STRING} !lang(.+)language
    RewriteCond %{QUERY_STRING} !langage(.+)lang
    # Looking for lang or language and saving other get values
    RewriteCond %{QUERY_STRING} ^(.+&|)lang(|uage)=([^&]+)(&.+|)$ 
    RewriteRule ^(.+)$ /$1?%1lang=%3&language=%3%4 [L]
    

    To try, add R – [R,L] to see redirect in browser address tab

Comments are closed.