简体   繁体   中英

Htaccess rule to nginx

i'm trying to rewrite the htaccess rule to nginx rule. this rule is used to load a php page for robot (like google robot).

here my htaccess:

RewriteCond %{HTTP_HOST} ^localhost$ [NC]
RewriteCond %{REQUEST_URI} ^/faq/$
RewriteCond %{QUERY_STRING} ^(.*)_escaped_fragment_=(.*)$
RewriteRule ^(.*)$ /files/snapshot_loader.php?snapshot_page=%1%2 [L]

can you help me ? i try this one, but redirect never work....

 location /faq {
        if ($query_string ~ "^(.*)test(.*)$"){
          RewriteRule  ^(.*)$ http://www.google.com permanent
        }
    }

Thanks in advance

First, there is no $query_string variable in nginx. And the second thing is there is no RewriteRule directive in nginx.

In nginx, the query string is stored in $args and you want the rewrite directive:

Try something like:

location /faq {
  if ($http_host ~* "^localhost$") {
    if($args ~* "^(.*)_escaped_fragment_=(.*)$") {
      set $newargs $1$2
      set $args '';
      rewrite ^ /files/snapshot_loader.php?snapshot_page=$newargs
    }
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM