jkumar_99
jkumar_99

Reputation: 61

Nginx rewrite not working as per docs

I am trying to redirect http://example.com/test/index.php?/Server/Search/IP_ADDRESS to http://example.com/?ip=IP_ADDRESS

Tried following rewrite rule, but, it is not working.

rewrite ^/test/index.php?/Server/Search/(.*)$ http://example.com/?ip=$1 redirect;

This is needed for internal purpose as another api will check the IP address at http://example.com/?ip=IP_ADDRESS

Upvotes: 0

Views: 58

Answers (1)

Dmitry MiksIr
Dmitry MiksIr

Reputation: 4455

location = /test/index.php {
  if ($args ~ "^/Server/Search/(.+)") {
     set $sip $1;
     rewrite ^(.*)$ /?ip=$sip? redirect;
  }
}

Upvotes: 2

Related Questions