Rewriting pages to re-rendered snapshots

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
snapshot:

    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
Website Hosting - Mysite.com 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
requested?

Thanks!

Posted at Nginx Forum:

I’m sure others will give you better methods to sort this but, as a
temporary fix, how about a separate stanza like this:

location = / {
#special index.html UA-sniffing + rewrite logic
}

Cheers,
Jonathan

Not sure what you mean Jonathan, I can already detect the Google bot by
using ?_escaped_fragment= which is also Google’s preferred way over user
agent sniffing. I just need to adapt the rewrite rule to serve
index.html to
requests for /.

Thanks for the reply, though!

Posted at Nginx Forum:

Duplicate your entire “location / {}” as “location = / {}” (which
matches only “/”), and when you detect google, serve
/snapshots/whatever/index.html.

Jonathan