Need help in URL Rewrite using Tuckey URL Rewrite in Struts2

后端 未结 1 1156
说谎
说谎 2021-01-14 04:10

I want to rewrite the URL for my Struts2 based application(currently in development environment). I have searched for it and found about Tuckey URL Rewrite and set it up in

相关标签:
1条回答
  • 2021-01-14 05:09

    To rewrite to this URL http://localhost:8080/login you have to deploy urlrewrite filter to the root context. But the application is running at the /MyProject context. You can't have both filters in the same application deployed to the same context to perform desired.

    How rewrite URL works: first you access the URL that you want to show, then urlrewrite filter searches the rules and if it find the match the rule is executed and request is forwarded (by default) to the new URL which is hidden for the user.

    If you use type="redirect" in the <to> tag the new URL will show up, because it means

    Requests matching the "conditions" and the "from" for this rule will be HTTP redirected. This is the same a doing: HttpServletResponse.sendRedirect([to value]))

    To rewrite URL you should use this rule deployed to the app at the root context

    <rule>
      <from>^/login$</from>
      <to type="redirect">/MyProject/loadLogin.action</to>
    </rule>
    
    0 讨论(0)
提交回复
热议问题