Support » Plugin: Polylang » Nginx fastcgi_cache and Polylang homepage redirect

  • Hi All,

    Just to share some tips (from experience and the discussion on https://rtcamp.com/support/topic/nginx-fastcgi-caching-and-redirects/) about Polylang on an Nginx server that uses the very fast fastcgi_cache which caches the usual WordPress responses to memory and thus saves PHP parsing time on each request, resulting in even lower server load and even better response times than Nginx alone.

    Since more and more web servers are using Nginx instead of Apache, more and more will also start using the fantastic fastcgi_cache system. I highly recommend to use the plugin Nginx Helper http://wordpress.org/plugins/nginx-helper/ and all the excellent tutorials and support that come with it!

    The problem: When the Polylang setting “Detect browser language: When the front page is visited, set the language according to the browser preference” is checked, then the first visitor that comes along will get redirected to his/her language correctly but… that redirect response will be cached by Nginx! Now subsequent visitors with different browser languages will get served the same cached response and so they will be redirected to the wrong language.

    The solution: To make Nginx cache and Polylang understand each other nicely, each will need one particular setting:
    1. Fastcgi_cache has a parameter fastcgi_cache_valid to control both cache time and which responses. When it is set like fastcgi_cache_valid 60m; then the reponses 200 OK, 301 Moved Permanently and 301 Found are cached for 60 minutes. Change that setting to fastcgi_cache_valid 200 60m; and only 200 OK responses will be cached.
    2. Make sure the Polylang option “Hide URL language information for default language” is NOT checked.

    The result is that the redirect from the root URL is not cached and each visitor will get redirected according to either their browser language or pll_language cookie value to the correct /xx/ dedicated language home URL. These language home pages themselves are cached so your server and your visitors will still (to most extent) benefit from caching.

    Good luck, and please share other/related tweaks 🙂

    http://wordpress.org/plugins/polylang/

Viewing 1 replies (of 1 total)
  • Plugin Author Chouby

    (@chouby)

    Hi RavanH! Thanks for sharing. I am sure it will be helpful. I added a link to this topic in the FAQ.

Viewing 1 replies (of 1 total)
  • The topic ‘Nginx fastcgi_cache and Polylang homepage redirect’ is closed to new replies.