diff --git a/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RewritePatternRule.java b/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RewritePatternRule.java index 59f3f3a97b3..b177d0410e2 100644 --- a/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RewritePatternRule.java +++ b/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RewritePatternRule.java @@ -90,13 +90,15 @@ public class RewritePatternRule extends PatternRule implements Rule.ApplyURI @Override public void applyURI(Request request, String oldURI, String newURI) throws IOException { + String queryString = request.getQueryString(); if (_query == null) { request.setURIPathQuery(newURI); + if (queryString != null) + request.setQueryString(queryString); } else { - String queryString = request.getQueryString(); if (queryString != null) queryString = queryString + "&" + _query; else diff --git a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewritePatternRuleTest.java b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewritePatternRuleTest.java index 30f856dc0f7..a69e253a47d 100644 --- a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewritePatternRuleTest.java +++ b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewritePatternRuleTest.java @@ -29,7 +29,7 @@ import static org.hamcrest.Matchers.is; public class RewritePatternRuleTest extends AbstractRuleTestCase { // TODO: Parameterize - private String[][] _tests = + private final String[][] _tests = { {"/foo/bar", "/", "/replace"}, {"/foo/bar", "/*", "/replace/foo/bar"}, @@ -98,8 +98,8 @@ public class RewritePatternRuleTest extends AbstractRuleTestCase assertThat("result matches expected", result, is(replacement)); rewritePatternRule.applyURI(_request, null, result); - assertThat("queryString matches expected", _request.getQueryString(), is(queryString)); assertThat("request URI matches expected", _request.getRequestURI(), is(replacement)); + assertThat("queryString matches expected", _request.getQueryString(), is(queryString)); } @Test