0

I want to redirect a string to different URL in nginx.

This what my vhost looks like and is working fine.

server {
  listen  80;
  server_name secure.example.com;
  root /opt/tomcat/webapps/test/;
  rewrite ^/Crest(.*)$ /$1;
  location / {
    proxy_pass                          http://127.0.0.1:8080/Crest;
    proxy_set_header Host               $host;
    proxy_set_header X-Real-IP          $remote_addr;
    proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
  }

}

Now I just want to redirect http://secure.example.com/Crest?page=login to http://example.com or /Crest?page=login to http://example.com.

  • @MichaelHampton : I have tried lot of things, but deleted once which were not working. Let me specify few of them I used MAP and the called $new in location as rewrite ^ $new redirect; I also used SCHEME, but that didn't work for me. rewrite ^/Crest?page=login $scheme://example.com permanent; if ( $query_string ~ /Crest?page=login ) { rewrite ^ http://example.com/? permanent; } – user3355434 Jul 06 '14 at 00:52
  • @MichaelHampton where am I making mistake, please let me know. – user3355434 Jul 06 '14 at 01:21
  • I think the problem with both of your attempts is that you are trying to compare `$query_string` with the full URI of the document. `$query_string` contains only the part after `?` in the URI, so the comparison doesn't work. – Tero Kilkanen Jul 06 '14 at 01:39

1 Answers1

0

You cannot achieve the goal you want in nginx. You have to make the redirection inside your application, that is, add the code to page=login part of the app.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63
  • Its working fine, I just want ?page=login to be executed and then redirected to http://example.com. Currently what is happening is that the page is not getting logged out and it is directly redirecting to the url. – user3355434 Jul 06 '14 at 02:39
  • Ah, that is completely different then.. I edited my answer. You need to ensure that the code in `page=login` to make the redirect to `example.com`. nginx cannot do that. – Tero Kilkanen Jul 06 '14 at 10:49