S
S
SaTaR2014-04-24 14:08:50
Nginx
SaTaR, 2014-04-24 14:08:50

How to compose nginx config file for google bot redirect?

There is a site on ajax. He has a static snapshot in the directory
_escaped_fragment_
. You need to write a rule to redirect the Google bot request to the static version of the site.
An example of a static address: Googlebot
/_escaped_fragment_/page/nerjav/index.html
request:

"GET /?_escaped_fragment_=/page/nerjav HTTP/1.1" 404 232 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"

My code doesn't work correctly:
# nginx configuration
location / {
if ($query_string ~ "^_escaped_fragment_=$"){
rewrite ^(.*)$ /_escaped_fragment_$1/index.html? break;
}
if ($query_string ~ "^_escaped_fragment_=(.*)$"){
rewrite ^(.*)$ /_escaped_fragment_$1/%1/index.html? break;
}
}

Returns:
HTTP/1.1 404 Not Found
Server: nginx/1.4.3
Date: Thu, 24 Apr 2014 10:11:01 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Content-Encoding: gzip

errorlog:
2014/04/24 16:43:14 [error] 6087#0: *1 rewrite or internal redirection cycle while processing "/_escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment_//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html", client: 66.249.66.194, server: m-chel.ru, request: "GET /?_escaped_fragment_=/page/nerjav HTTP/1.1", host: "test1.ru"
2014/04/24 16:43:56 [error] 6087#0: *2 rewrite or internal redirection cycle while processing "/_escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment_//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html", client: 109.191.139.106, server: m-chel.ru, request: "GET /?_escaped_fragment_=/page/nerjav HTTP/1.1", host: "test1.ru"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vitaliy2, 2018-02-05
@vitaliy2

Try like this:
And how do you make a request to your server?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question