【问题标题】:Htaccess rule to nginxnginx 的 Htaccess 规则
【发布时间】:2015-12-29 12:25:58
【问题描述】:

我正在尝试将 htaccess 规则重写为 nginx 规则。 此规则用于为机器人(如谷歌机器人)加载 php 页面。

这里是我的 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]

你能帮帮我吗?我试试这个,但重定向永远不会工作....

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

提前致谢

【问题讨论】:

    标签: apache .htaccess nginx


    【解决方案1】:

    首先,nginx 中没有$query_string 变量。第二件事是nginx中没有RewriteRule指令。

    在 nginx 中,查询字符串存储在 $args 中,您需要 rewrite 指令:

    尝试类似:

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

    【讨论】:

      猜你喜欢
      • 2020-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-27
      相关资源
      最近更新 更多