Score:0

How to redirect to /index.php?/Test/ in nginx?

ru flag

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.

drookie avatar
za flag
The '?' literal is a separator which stands between URI and GET arguments. Get arguments are stored in $arg_<name> 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.
us flag
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.
djdomi avatar
za flag
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
M. Jeremy avatar
ru flag
@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.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.