简体   繁体   中英

UrlRewriteFilter - combining redirect and forward rules

I'm trying to tame urlrewritefilter, and it looks like like when one rule with redirect matchs another rule with forward I won't see the URL I'm redirecting in the address bar, as expected.

Here is a snippet of config:

<rule>
  <from>/patha</from>
  <to type="redirect">/pathb</to>
</rule>

<rule>
  <from>/pathb</from>
  <to type="forward">/pathc</to>
</rule>

What I am expecting to be done by this rules while I'm trying to access to patha

  • Rule for patha redirect my browser to pathb , the URL in address bar is changing .
  • Since this rule is not the last one, the rule for pathb is also a good match, so browser get forwarded to pathc, but, because this is forward, the URL in address bar remains pathb .

But actually what is happening is that I'm forwarding to pathc without any changes in address bar.

My question is: Why is this so and how I can actually achieve what I am seeking for?

UPD: I've tested urlrewritefilter forward with redirection in jsp via:

response.setStatus(302);
response.setHeader("Location", "pathb");
response.setHeader("Connection", "close");

The result is the same - URL is not rewritten.

What you are noticing is the expected behaviour. With forward you will never see the URL in the browser. Please see below differences between forward and redirect :

Forward

  • a forward is performed internally by the servlet, the browser is completely unaware that it has taken place, so its original URL
  • remains intact any browser reload of the resulting page will simple repeat the original request, with the original URL

Redirect

  • a redirect is a two step process, where the web application instructs the browser to fetch a second URL, which differs from the original a browser reload of the second URL will not repeat the original request, but will rather fetch the second URL
  • redirect is marginally slower than a forward, since it requires two browser requests, not one objects placed in the original request scope are not available to the second request

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