Rewriting pages to re-rendered snapshots

rootberry nginx-forum at
Mon Jul 1 10:26:14 UTC 2013

I have a very Javascript heavy website which is being served by nginx. It
all works great, except Google is having trouble indexing me. I've made
pre-rendered snapshots of all my pages using Phantomjs and these are stored
in /snapshots (relative to my website's root).

I've been using this rewrite rule to detect the Google bot and serve it a

        location / {

                if ($args ~ "_escaped_fragment_=") {
                        rewrite ^/(.*)$ /snapshots/$1.html break;


It works for all pages apart from the homepage. In the snapshots directory,
the home page is called index.html, however the Google bot requests when it wants the home page, which
makes this rewrite rule return a 404.

How can I adapt this rule to return the index.html snapshot when / is


Posted at Nginx Forum:,240435,240435#msg-240435

More information about the nginx mailing list