I have configured Tuckey URL Rewriting. I have included dependency in pom.xml
:
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>4.0.4</version>
</dependency>
added filter in 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>commons</param-value>
</init-param>
<init-param>
<param-name>confReloadCheckInterval</param-name>
<param-value>60</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>
created urlrewriter.xml
under WEB-INF
folder
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.0//EN"
"http://www.tuckey.org/res/dtds/urlrewrite3.0.dtd">
<urlrewrite default-match-type="wildcard">
<!-- Struts -->
<rule match-type="regex">
<from>^/Profile/([0-9]+)$</from>
<to>/Profile?id=$1</to>
</rule>
<!-- Remove JSESSIONID from URLs when cookies disabled -->
<!-- http://stackoverflow.com/questions/962729/is-it-possible-to-disable-jsessionid-in-tomcat-servlet -->
<outbound-rule encodefirst="true" match-type="regex">
<name>Strip URL Session ID's</name>
<from>^(.*?)(?:\;jsessionid=[^\?#]*)?(\?[^#]*)?(#.*)?$</from>
<to>$1$2$3</to>
</outbound-rule>
</urlrewrite>
Now from browser I am requesting http://localhost:8080/Test/Profile/123
This in not redirection to http://localhost:8080/Test/Profile?id=123
How to make this working?
EDIT:
At debug I am getting following result at Tomcat log
24-Jan-2018 17:06:45.588 INFO [http-nio-8084-exec-163] org.apache.catalina.core.ApplicationContext.log org.tuckey.web.filters.urlrewrite.UrlRewriteFilter DEBUG: starting conf reload check
24-Jan-2018 17:06:45.589 INFO [http-nio-8084-exec-163] org.apache.catalina.core.ApplicationContext.log org.tuckey.web.filters.urlrewrite.UrlRewriteFilter DEBUG: conf is not modified
24-Jan-2018 17:06:45.589 INFO [http-nio-8084-exec-163] org.apache.catalina.core.ApplicationContext.log org.tuckey.web.filters.urlrewrite.utils.ServerNameMatcher DEBUG: looking for hostname match on current server name localhost
24-Jan-2018 17:06:45.589 INFO [http-nio-8084-exec-163] org.apache.catalina.core.ApplicationContext.log org.tuckey.web.filters.urlrewrite.UrlRewriteFilter DEBUG: checking for status path on /test/Profile/2345
24-Jan-2018 17:06:45.589 INFO [http-nio-8084-exec-163] org.apache.catalina.core.ApplicationContext.log org.tuckey.web.filters.urlrewrite.UrlRewriter DEBUG: processing request for /Profile/2345
24-Jan-2018 17:06:45.590 INFO [http-nio-8084-exec-163] org.apache.catalina.core.ApplicationContext.log org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Rule 0 run called with /Profile/2345
24-Jan-2018 17:06:45.590 INFO [http-nio-8084-exec-163] org.apache.catalina.core.ApplicationContext.log org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: matched "from"
24-Jan-2018 17:06:45.590 INFO [http-nio-8084-exec-163] org.apache.catalina.core.ApplicationContext.log org.tuckey.web.filters.urlrewrite.substitution.MatcherReplacer DEBUG: found 1
24-Jan-2018 17:06:45.590 INFO [http-nio-8084-exec-163] org.apache.catalina.core.ApplicationContext.log org.tuckey.web.filters.urlrewrite.substitution.MatcherReplacer DEBUG: replaced sb is /Profile?id=2345
24-Jan-2018 17:06:45.590 INFO [http-nio-8084-exec-163] org.apache.catalina.core.ApplicationContext.log org.tuckey.web.filters.urlrewrite.RuleExecutionOutput DEBUG: needs to be forwarded to /Profile?id=2345
24-Jan-2018 17:06:45.590 INFO [http-nio-8084-exec-163] org.apache.catalina.core.ApplicationContext.log org.tuckey.web.filters.urlrewrite.UrlRewriter DEBUG: rule is last
24-Jan-2018 17:06:45.590 INFO [http-nio-8084-exec-163] org.apache.catalina.core.ApplicationContext.log org.tuckey.web.filters.urlrewrite.UrlRewriteFilter DEBUG: starting conf reload check
24-Jan-2018 17:06:45.590 INFO [http-nio-8084-exec-163] org.apache.catalina.core.ApplicationContext.log org.tuckey.web.filters.urlrewrite.UrlRewriteFilter DEBUG: conf is not modified
24-Jan-2018 17:06:45.591 INFO [http-nio-8084-exec-163] org.apache.catalina.core.ApplicationContext.log org.tuckey.web.filters.urlrewrite.utils.ServerNameMatcher DEBUG: looking for hostname match on current server name localhost
24-Jan-2018 17:06:45.591 INFO [http-nio-8084-exec-163] org.apache.catalina.core.ApplicationContext.log org.tuckey.web.filters.urlrewrite.UrlRewriteFilter DEBUG: checking for status path on /test/Profile
24-Jan-2018 17:06:45.591 INFO [http-nio-8084-exec-163] org.apache.catalina.core.ApplicationContext.log org.tuckey.web.filters.urlrewrite.UrlRewriter DEBUG: processing request for /Profile
24-Jan-2018 17:06:45.591 INFO [http-nio-8084-exec-163] org.apache.catalina.core.ApplicationContext.log org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Rule 0 run called with /Profile
Tomcat console is showing:
MonitorFilter::WARNING: the monitor filter must be the first filter in the chain.