开发者

How to make UrlRewrite to change my address?

Need to get rid of jsessionid from my url. After some research on the internet a found out that UrlRewrite can do that.

So I created a rule for it. Here is the xml file (urlrewrite.xml) :

<urlrewrite>
    <rule>
        <name>Strip SessionID</name>
        <note>Strip all URLs of Session ID</note>
        <from>^(.*)(;jsessionid=[a-zA-Z0-9]{32})(.*)$</from>
        <to encode="false">$1$3</to>
    </rule>
</urlrewrite>

The problem is it does not quite work. Is my rule correct ?

I tried debuging a bit. And I used this rule:

<rule>
  <name>Strip SessionID<开发者_Python百科/name>
  <note>Strip all URLs of Session ID</note>
  <from>initialPage.jsp</from>
  <to encode="false">redirectPage.jsp</to>
</rule>

Going to the browser and entering http://localhost:8080/initialPage.jsp and hitting enter (of course) I get a big surprize. It works.

I get redirected to redirectPage.jsp. I mean I see that page.

But here is the trick : the url in the address bar of the browser has not changed.

How, in the world, does this UrlRewrite help me get rid of jsessionid if I still see it there ? Any ideas ? How to configure a rule to help me NOT see that ?


It's not quite clear what are you trying to achieve. To get rid of jsessionid you need to process URLs generated by your application, not the incoming URLs, therefore you need to specify <outbound-rule>, see the corresponding example here.

Regarding the seciond snippet - by default UrlRewriteFilter forwards your request to the new address, not redirects it, so address bar remains the same. You can configure it to redirect your request by using <to type = "redirect">.


On a similar quest some months back, I had come across this article - it helped me to get rid of the niggling problem posed by the jsessionid parameter in the URL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜