this is my first posting here, if i missed something please be indulge.

I have got a htaccess rule:

RewriteCond %{QUERY_STRING} ^soap=([^&]+)
RewriteRule ^/?index\.php$ http://backendserver.com  /index.php?soap=%1 [L,R=302]

The requests:


are both redirecting me to the Backend-Server. So far so good.

Now im trying to move from apache2 to nginx.

location / {
if ($args ~ "^soap=([^&]+)"){
   #return 404;
   rewrite ^/?index\.php$ http://www.zam24.de/index.php?soap=%1 redirect;

Now i got 2 Problems that i can not handle alone:

  1. I dont get redirected, but if replace the "rewrite..." with "return 404;" i get a 404.

  2. If I request index.php?soap=123 and not just ?soap=123 it will ignore the rewrite rule and "execute" the index.php

My full nginx-config can be found on: http://pastebin.com/ULRyNeZ4

Thanks for your help!


You should be able to use this configuration:

location / {
    if ($arg_soap) {
         rewrite ^ http://www.zam24.de/index.php?soap=$arg_soap redirect;

We test here for the soap argument in the query string. If it is found, we rewrite the URL to the destination and pass the soap argument to the rewrite destination.

We don't need to use regex matching / capturing, since nginx already has query string arguments available in variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.