Search code examples
javamavenweb-applicationsdeploymenttuckey-urlrewrite-filter

How to configure maven urlrewrite


So we are currently supporting two web apps and want to stop doing so in the near future. So all urls targeting the old maven project we want to redirect to a static page.

To do so I have:

1- Added the following dependency:

<dependency>
  <groupId>org.tuckey</groupId>
  <artifactId>urlrewritefilter</artifactId>
  <version>4.0.3</version>
</dependency>

2- Added the following to my web.xml file (after jstl setup and before servlet setup)

<filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>

And then added a urlrewrite.xml file with the following rule just for testing:

<urlrewrite>
    <rule>
        <from>http://localhost/start/of/url/ (the actual start of the url)</from>
        <to type="redirect">http://www.google.com/</to>
    </rule>
</urlrewrite>

I am totally new to this concept/configurations as I am working on a spring project but have to modify this maven web app that is not in spring. So the redirection is not taking effect and not affecting the flow at all, any idea?

Update: I changed the from tag to /* that worked, but the page it is redirecting me to is http://www.google.com/http://www.google.com/http://www.google.com/http://www.google.com/ (several times after each other), any ideas?


Solution

  • <urlrewrite>
    <rule>
        <from>^(.*)</from>
        <to type="redirect">http://www.google.com/</to>
    </rule>
    </urlrewrite>
    

    Try this, it should work... tested...