http - nginx rewrite rules: The page jumps successfully but the browser address bar does not change
黄舟
黄舟 2017-05-16 17:20:33
0
2
771

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?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(2)
淡淡烟草味

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.

巴扎黑

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!