How do I redirect/handle requests from search engines via nginx using location regex How do I redirect/handle requests from search engines via nginx using location regex nginx nginx

How do I redirect/handle requests from search engines via nginx using location regex


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

Note that locations of all types test only a URI part of request line without arguments. This is done because arguments in the query string may be given in several ways, for example:

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

You could setup a rewrite rule in the server section (found here):

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

and define a "/crawler" location, which can be redirected to your HTML generating server.


I solved this problem this way:

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