Question

I am trying to redirect old servlet urls to new ones with UrlRewriteFilter 4.0.3. I have a bunch of working rules but the one with a servlet url in <from></from> is not working.

My rule looks like this:

<rule>
    <from>/servlet/OldServlet\?old_parameter=&amp;id=([0-9]+)$</from>
    <to type="redirect">/servlet/NewServlet?new_parameter=&amp;document_id=$1</to>
</rule>

I have tried to cut out pieces of the "from" with ".+". I managed to get the rule working by removing "?" from my url and rule. It seems that servlet urls are not matched to defined rules. OldServlet is still mapped in my web.xml for legacy reasons.

EDIT:

org.tuckey.web.filters.urlrewrite.UrlRewriter DEBUG: processing request for /servlet/OldServlet

The url gets trimmed from "?".

EDIT 2:

UrlRewriter.java:

public String getPathWithinApplication(HttpServletRequest request) {
    String requestUri = request.getRequestURI();
    ...

It seems that UrlRewriteFilter uses a method that does not return the full url.

http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getRequestURI()

Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.

Was it helpful?

Solution

Query string isn't appended by default. Started to work after I added use-query-string="true" attribute to urlrewrite.

<urlrewrite use-query-string="true">
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top