简体   繁体   English

我可以在不运行ZF2应用程序两次的情况下从URL重定向到另一个URL吗?

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

I want to redirect a user from one url to another. 我想将用户从一个URL重定向到另一个。 I used $this->redirect()->toRoute() but i've noticed that the application runs twice as if the user made 2 requests. 我使用$this->redirect()->toRoute()但我注意到该应用程序运行两次,就像用户发出了2个请求一样。

Of course you have 2 requests. 当然,您有2个请求。 Because the following will happen: 因为会发生以下情况:

  1. Request to /someroute 要求/ someroute
  2. Response from someroute will contain "go to /otherroute" 来自某条路线的响应将包含“转到/ otherroute”
  3. Request to /otherroute 要求/ otherroute
  4. Response HTML 响应HTML

Maybe a workaround is not to use redirect() , but forward() . 可能的解决方法是不使用redirect() ,而使用forward() The disadvantage is that you are still on /someroute while getting response from /otherroute . 缺点是,你还在上/someroute同时获得来自响应/otherroute

I'm not very familiar with ZF2, but in PHP you can use 我对ZF2不太熟悉,但是可以在PHP中使用

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

Can you try it? 你可以试试看吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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