1
votes

I´d need to forward a url like

http://localhost:8080/doc/service?type=testLogin&exectype=userShow&moreparms

to:

http://localhost:8080/xyz/service?type=testLogin&exectype=userShow&moreparms

The system runs with tomcat 8.0.28 and has already the URLRewriteFilter (http://www.tuckey.org/urlrewrite/) loaded, but is not working with the follow specific code that i mentioned on the urlrewritefilter-site at googlecode.com that needs to be put in the webapps/doc/WEB-INF/web.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     version="2.5">

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

And i added the follow rule to urlrewrite.xml in the same directory as web.xml:

<urlrewrite>
    <rule>
       <from>^/doc/(.*)$</from>
       <to type="redirect">/xyz/$1</to>
    </rule>

    <outbound-rule>
    </outbound-rule>
<urlrewrite>

I'm getting 404's when trying to go to something like

http://localhost:8080/doc/service?type=testLogin&exectype=userShow&moreparms

I get the 404 error also if i try

http://localhost:8080/doc/status

with the example-rule like:

<urlrewrite>
    <rule>
        <from>/doc/status/</from>
        <to type="redirect">%{context-path}/rewrite-status</to>
    </rule>
    <outbound-rule>
       <from>/rewrite-status</from>
       <to>/doc/status/</to>
    </outbound-rule>
<urlrewrite>

But

http://localhost:8080/doc/rewrite-status

works.

Where is my fault?

P.S: I`m using Win10 pro and urlrewritefilter-4.0.3

1

1 Answers

0
votes
<rule>
   <from>^/doc/(.*)$</from>
   <to type="redirect">/xyz/$1</to>
</rule>

The <from> and <to> in your rule should be exchanged. Try something like:

<rule match-type="wildcard">
   <from>^/xyz/**</from>
   <to>/doc/$1</to>
</rule>

The above will forward requests for /xyz/** to /doc/** as stated in UrlRewriteFilter - Manual

Outbound rules are similar to <rule> but process URLs that are passed to response.encodeURL().