How to redirect / process queries from search engines using nginx using regex location

I developed an ajax based web application with hash bang urls.

I am trying to redirect requests from search engines to another server that generates HTML snapshots and sends a response. I am trying to achieve this in nginx with a location directive as follows:

      location ~ ^(/?_escaped_fragment_=).*$ {
         proxy_set_header        Host $host;
          proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header        X-Forwarded-Proto $scheme;

          client_max_body_size    10m;
          client_body_buffer_size 128k;
          proxy_connect_timeout   60s;
          proxy_send_timeout      90s;
          proxy_read_timeout      90s;
          proxy_buffering         off;
          proxy_temp_file_write_size 64k;
          proxy_pass      http://x1.x2.x3.x4:8080;
          proxy_redirect      off;
      }

But I can't get this to work. Can someone fix the regex that I use (or) provide me with an alternative solution to achieve this.

Thanks in advance.

+5
source share
2 answers

You cannot check the arguments in the location name ( nginx docs ):

, URI . , , :

/index.php?user=john&page=1
/index.php?page=1&user=john

( ):

if ($args ~ "_escaped_fragment_=(.+)") {
    set $real_url $1;
    rewrite ^ /crawler$real_url;
}

"/", HTML.

+5

:

if ( $arg__escaped_fragment_ ) {
    return 301 $uri$arg__escaped_fragment_;
}
+1

All Articles