Question

My project (we have Spring 3) needs to rewrite URLs from the form

localhost:8888/testing/test.htm?param1=val1&paramN=valN 

to

localhost:8888/nottestinganymore/test.htm?param1=val1&paramN=valN

My current rule looks like:

<from>^/testing/(.*/)?([a-z0-9]*.htm.*)$</from>
<to type="passthrough">/nottestinganymore/$2</to>

But my query parameters are being doubled, so I am getting param1=val1,val1 and paramN=valN,valN...please help! This stuff is a huge pain.

To edit/add, we have use-query-string=true on the project and I doubt I can change that.

No correct solution

OTHER TIPS

The regular expression needs some tweaking. Tuckey uses the java regular expression engine unless specified otherwise. Hence the best way to deal with this is to write a small test case that will confirm if your regular expression is correct. For e.g. a slightly tweaked example of your regular expression with a test case is below.

@Test public void testRegularExpression()
{
    String regexp = "/testing/(.*)([a-z0-9]*.htm.*)$";
    String url = "localhost:8888/testing/test.htm?param1=val1&paramN=valN";

    Pattern pattern = Pattern.compile(regexp);

    Matcher matcher = pattern.matcher(url);

    if (matcher.find())
    {
        System.out.println("$1 : " + matcher.group(1) );
        System.out.println("$2 : " + matcher.group(2) );
    }
}

The above will print the output as follows :

$1 : test

$2 : .htm?param1=val1&paramN=valN

You can modify the expression now to see what "groups" you want to extract from URL and then form the target URL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top