问题
I need to redirect a URL in nginx. My rule looks like this which actually causes the browser to visibly change the URL, which is not what is expected.
location / {
rewrite ^/dentists/bangalore/indiranagar/$ http://abc.com/doctorsInArea.htm?cID=bangalore&aID=indiranagar break;
}
I read another question here nginx rewrite WITHOUT change url which tells me to remove the http part . I tried
location / {
rewrite ^/dentists/bangalore/indiranagar/$ /doctorsInArea.htm?cID=bangalore&aID=indiranagar break;
}
This one throws a 404 even though http://abc.com/doctorsInArea.htm?cID=bangalore&aID=indiranagar works fine when hit from the browser. Any insights on the problem would be apprreciated.
回答1:
I got it working by using the following.
location / {
rewrite "/dentists/bangalore/indiranagar/" /doctorsInArea.htm?cID=bangalore&aID=indiranagar last;
}
Thanks!
来源:https://stackoverflow.com/questions/15544342/nginx-url-rewrite-changes-url