search

Home  >  Q&A  >  body text

http - nginx rewrite rules: The page jumps successfully but the browser address bar does not change

This is written in the configuration:

location / {
        rewrite /bug.html /weather/index.html?mode=test last;
        error_page 404 = @nodejs;
}

When the browser opens /bug.html, the /weather/index.html page does appear, but the browser address bar does not change.
How is this going?

黄舟黄舟2860 days ago894

reply all(2)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-16 17:22:33

    Try changing it to this

    location / {
            rewrite /bug.html /weather/index.html?mode=test redirect;
            error_page 404 = @nodejs;
    }

    There are many ways to rewrite, and the one you wrote actually means 用户访问老地址时,服务器到新地址去抓取内容然后展现,看清楚了吗,你可以理解为服务器内部做了个跳转,而外部地址不会改变。如果你想让浏览器直接去访问新地址,请用redirect.

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-16 17:22:33

    Single rewrite is a server redirection: nginx grabs another url and returns it to the current request

    The kind you want is client redirection: nginx returns 301/302 to the current request, letting the browser request the new url by itself

    reply
    0
  • Cancelreply