Above your rewrite line add:
rewrite ^/$ /index.html;
Question
I have a very Javascript heavy application which I'd like to get indexed. I have a directory of snapshots on my website which can be served to the Google bot. These are under mysite.com/snapshots/
.
I'm using the following rewrite rule to serve the snapshot to the Google bot:
location / {
if ($args ~ "_escaped_fragment_=") {
rewrite ^/(.*)$ /snapshots/$1.html break;
}
}
This works for all of my snapshots except the home page. The problem is, the homepage gets saved as mysite.com/snapshots/index.html
. When the Google bot requests mysite.com/?_escaped_fragment_=
, nginx tried to serve /snapshots/.html
and obviously the request 404's.
I need to adapt the rewrite rule to serve up index.html when the document root is requested.
Cheers!
Solution
Above your rewrite line add:
rewrite ^/$ /index.html;
OTHER TIPS
Add this to your server configuration, no matter where, just within server{}
.
location ^= index\.html$ {
try_files $uri =404;
}
This checks if there requested URL ends with index.html
. If this doesn't do the trick, I'd need full URLs as the Google bot requests them.