search

Home  >  Q&A  >  body text

http - How to make nginx's rewrite rule (redirect) execute only once?

rewrite ^/(.*).html$ /.html?mode=test redirect;

Now there is a rewrite rule like the above, which can take effect, but it will redirect multiple times. How to modify it so that it only jumps once?

Using break will not work, because break will not modify the browser address bar.

For example:
http://xxx.xx.xx/weather/bug.htmlwill keep jumping and weather/bug.html?mode=test&mode=test&mode= will appear test&mode=test&mode=test&mode=test&mode=test&mode=test&mode……

renew

    location / {
            if($args *~ "mode=formal"){
                rewrite (.*) ? redirect;
                rewrite (.*) ?mode=test redirect;
            }
            else if($args [[不包含mode=test]]){
                rewrite ^/(.*).html$ /.html?mode=test redirect;
            }
            error_page 404 = @nodejs;
    }

I want to configure it in the above way, first judge $args, and then rewrite, I don’t know if it is possible.
And how should I write [[excluding mode=test]]?

某草草某草草2755 days ago605

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-05-16 17:22:30

    Let’s try using last

    reply
    0
  • Cancelreply