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 my project. Now i want my login url which is currently http://localhost:8080/MyProject/loadLogin.action
(I am using Wildcard mapping in Struts2) to look like http://localhost:8080/login
.
Below is my configuration code:
struts.xml:
<action name="*Login" method="{1}" class="com.myproject.controller.LoginController">
<result name="login" type="tiles">mylogin</result>
</action>
web.xml:
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>logLevel</param-name>
<param-value>DEBUG</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Now here's the urlrewrite.xml which has the rule and I do not know if I have configured the rule correctly:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
"http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">
<!--
Configuration file for UrlRewriteFilter
http://www.tuckey.org/urlrewrite/
-->
<urlrewrite>
<rule>
<from>^/*</from>
<to type="redirect">/login</to>
</rule>
</urlrewrite>