如何在 nginx 中重定向到 /index.php?/Test/?

如何在 nginx 中重定向到 /index.php?/Test/?

我有一台 nginx 服务器。我想将 /index.php?/Test/ 请求重定向到另一台服务器。我尝试了很多示例,但都没有成功。

我使用的例子:

location / {

    if ( $query_string = "/Ajax/" ) {

        return 301 http://localhost.com/index.php?/Ajax/;
    }

    location /index.php*/Test/ {
        return 301 http://localhost.com/Test;
    }
    
    location /index.php?/Test/ {
        return 301 http://localhost.com/Test;
    }

Nginx 调试:

022/03/18 18:29:08 [debug] 10022#0: *12 http request line: "POST /?/Test/ HTTP/1.1"
2022/03/18 18:29:08 [debug] 10022#0: *12 http uri: "/"
2022/03/18 18:29:08 [debug] 10022#0: *12 http args: "/Test/"
2022/03/18 18:29:08 [debug] 10022#0: *12 http exten: ""
2022/03/18 18:29:08 [debug] 10022#0: *12 posix_memalign: 00005614404B1200:4096 @16
2022/03/18 18:29:08 [debug] 10022#0: *12 http process request header line
2022/03/18 18:29:08 [debug] 10022#0: *12 http header: "Content-Type: application/x-www-form-urlencoded"
2022/03/18 18:29:08 [debug] 10022#0: *12 http header: "Host: my.localhost.com"
2022/03/18 18:29:08 [debug] 10022#0: *12 http header: "Content-Length: 22"
2022/03/18 18:29:08 [debug] 10022#0: *12 http header: "Expect: 100-continue"
2022/03/18 18:29:08 [debug] 10022#0: *12 http header done
2022/03/18 18:29:08 [debug] 10022#0: *12 generic phase: 0
2022/03/18 18:29:08 [debug] 10022#0: *12 rewrite phase: 1
2022/03/18 18:29:08 [debug] 10022#0: *12 test location: "/"
2022/03/18 18:29:08 [debug] 10022#0: *12 test location: ~ "\.php$"
2022/03/18 18:29:08 [debug] 10022#0: *12 using configuration "/"
2022/03/18 18:29:08 [debug] 10022#0: *12 http cl:22 max:1048576
2022/03/18 18:29:08 [debug] 10022#0: *12 rewrite phase: 3
2022/03/18 18:29:08 [debug] 10022#0: *12 http script regex: "^/index\.php?/Test/$"
2022/03/18 18:29:08 [notice] 10022#0: *12 "^/index\.php?/Test/$" does not match "/", client: 1.1.1.1, server: my.localhost.com, request: "POST /?/Test/ HTTP/1.1", host: "my.localhost.com"
2022/03/18 18:29:08 [debug] 10022#0: *12 post rewrite phase: 4
2022/03/18 18:29:08 [debug] 10022#0: *12 generic phase: 5
2022/03/18 18:29:08 [debug] 10022#0: *12 generic phase: 6
2022/03/18 18:29:08 [debug] 10022#0: *12 generic phase: 7
2022/03/18 18:29:08 [debug] 10022#0: *12 generic phase: 8
2022/03/18 18:29:08 [debug] 10022#0: *12 access phase: 9
2022/03/18 18:29:08 [debug] 10022#0: *12 access phase: 10
2022/03/18 18:29:08 [debug] 10022#0: *12 access phase: 11
2022/03/18 18:29:08 [debug] 10022#0: *12 post access phase: 12
2022/03/18 18:29:08 [debug] 10022#0: *12 generic phase: 13
2022/03/18 18:29:08 [debug] 10022#0: *12 generic phase: 14
2022/03/18 18:29:08 [debug] 10022#0: *12 content phase: 15
2022/03/18 18:29:08 [debug] 10022#0: *12 content phase: 16
2022/03/18 18:29:08 [debug] 10022#0: *12 open index "/var/www/test/public_html/index.php"
2022/03/18 18:29:08 [debug] 10022#0: *12 internal redirect: "/index.php?/Test/"
2022/03/18 18:29:08 [debug] 10022#0: *12 rewrite phase: 1
2022/03/18 18:29:08 [debug] 10022#0: *12 test location: "/"
2022/03/18 18:29:08 [debug] 10022#0: *12 test location: ~ "\.php$"
2022/03/18 18:29:08 [debug] 10022#0: *12 using configuration "\.php$"
    

我想以同样的方式将所有传入请求重定向到其他服务器。

相关内容