@@ -65,8 +65,9 @@ public boolean evaluate(final Rewrite event, final EvaluationContext context)
6565 String url = URL .build (path ).decode ().toURL ()
6666 + QueryString .build (httpRewrite .getInboundAddress ().getQuery ()).toQueryString ();
6767
68- if (url .startsWith (httpRewrite .getContextPath ()))
69- url = url .substring (httpRewrite .getContextPath ().length ());
68+ String contextPath = httpRewrite .getContextPath ();
69+ if (!contextPath .equals ("/" ) && url .startsWith (contextPath ))
70+ url = url .substring (contextPath .length ());
7071
7172 if (rule .matches (url ))
7273 {
@@ -86,8 +87,9 @@ public void perform(final Rewrite event, final EvaluationContext context)
8687 originalUrl = URL .build (originalUrl ).decode ().toURL ()
8788 + QueryString .build (httpRewrite .getInboundAddress ().getQuery ()).toQueryString ();
8889
89- if (originalUrl .startsWith (((HttpServletRewrite ) event ).getContextPath ()))
90- originalUrl = originalUrl .substring (((HttpServletRewrite ) event ).getContextPath ().length ());
90+ String contextPath = ((HttpServletRewrite ) event ).getContextPath ();
91+ if (!contextPath .equals ("/" ) && originalUrl .startsWith (contextPath ))
92+ originalUrl = originalUrl .substring (contextPath .length ());
9193
9294 String newUrl = engine .processInbound (((HttpServletRewrite ) event ).getRequest (),
9395 ((HttpServletRewrite ) event ).getResponse (), rule , originalUrl );
@@ -110,7 +112,7 @@ public void perform(final Rewrite event, final EvaluationContext context)
110112 /*
111113 * Add context path and encode request using encodeRedirectURL().
112114 */
113- redirectURL = (( HttpServletRewrite ) event ). getContextPath () + newUrl ;
115+ redirectURL = contextPath + newUrl ;
114116 }
115117 else if (StringUtils .isNotBlank (rule .getUrl ()))
116118 {
0 commit comments