• I’m using the latest version of Polylang (1.9.3) and have two languages (de & fr), with de being the default language. The language code for the default language and language based redirects are enabled. Unfortunately I can’t change that.

    So calling the page at https://www.example.com will redirect to https://www.example.com/de/ with the redirect code 302. I’d like to change this to a 301 redirect.

    I know this issue isn’t new and I’ve read about others (here and here).
    Since I can’t disable the language code and language based redirect I tried to apply the wp_redirect_status filter and modify the redirect code, as suggested by the plugin author.

    add_filter('wp_redirect_status', 'modify_status', 10, 2);
    function modify_status($status, $location) {
      $homepages = array(
        'https://www.example.com/de/',
        'https://www.example.com/fr/'
      );
    
      if (in_array($location, $homepages))
        return 301;
    }

    But this isn’t working. I even tried removing the check for $location like this.

    add_filter('wp_redirect_status', 'modify_status', 10, 2);
    function modify_status($status, $location) {
        return 301;
    }

    This changes other redirects I have on my page, so it’s definitely being called; still the first request for the page is being redirected with a 302.

    Any idea why the filter isn’t working for Polylang or any other suggestions how I could fix this?

    https://www.ads-software.com/plugins/polylang/

  • The topic ‘Change redirect code from 302 -> 301’ is closed to new replies.