shabunc
shabunc

Reputation: 24741

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

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.

Upvotes: 0

Views: 1878

Answers (1)

Ram G
Ram G

Reputation: 4829

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

Upvotes: 6

Related Questions