Nginx URL rewrite changes URL

北慕城南 提交于 2019-12-24 15:45:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!