简体   繁体   中英

Can I redirect from a URL to another without running ZF2 application twice?

I want to redirect a user from one url to another. I used $this->redirect()->toRoute() but i've noticed that the application runs twice as if the user made 2 requests.

Of course you have 2 requests. Because the following will happen:

  1. Request to /someroute
  2. Response from someroute will contain "go to /otherroute"
  3. Request to /otherroute
  4. Response HTML

Maybe a workaround is not to use redirect() , but forward() . The disadvantage is that you are still on /someroute while getting response from /otherroute .

I'm not very familiar with ZF2, but in PHP you can use

header('Location:www.url.com');

Can you try it?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM