0

I have a nginx server. I want to redirect /index.php?/Test/ request to another server. I tried many example but I don't successfully.

I used example:

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 Debug:

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$"
    

I want to redirect all incoming request to other server in the same way complete.

Tero Kilkanen
  • 34,499
  • 3
  • 38
  • 58
  • The '?' literal is a separator which stands between URI and GET arguments. Get arguments are stored in $arg_ variables, not in $query_string; furthermore in your case the name of Get argument is malformed since it starts with slash, so you cannot reference it. That's the number of factors that led you to the fiasco. – drookie Mar 19 '22 at 08:01
  • I reformatted the configuration snippet you have in your question. Are you sure it looks like that? It is missing the closing `}` for the root location. – Tero Kilkanen Mar 20 '22 at 10:23
  • i agreed with drookie, But just in mind, would it maybe possible to use a sub domain for your request? since it basically keep the structure but it may be proxy_pass'ed to a other server – djdomi Mar 20 '22 at 17:09
  • @drookie thank you for answer. Tero Kilkanen: I added to up line the codes, closing tag is bellow. I'am sorry. djdomi: I worked and tried but i did'nt. – M. Jeremy Mar 29 '22 at 10:21

0 Answers0