Rewrite from context path and full redirect to different server failures

588 views
Skip to first unread message

James M

unread,
Jan 11, 2011, 6:17:12 PM1/11/11
to UrlRewrite
It would appear that this bug still exists. Here is my configuration:

This is deployed to context /new. I want to forward to context /abc

<urlrewrite use-context="false">

<rule>
<note>
redirect
</note>
<from>/*</from>
<to type="redirect">/abc</to>
</rule>


web.xml:
<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>
<init-param>
<param-name>confReloadCheckInterval</param-name>
<param-value>0</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


Browsing to http://mydomain.com/new redirects to http://mydomain/abc/abc.
Why does it double up on the path?

If I change the to option to http://mydomain.com/abc then the redirect
is http://mydomain.com/abchttp://mydomain.com/abc

I'm running Jetty 6.1.5 on Ubuntu 10.04. Any idea why neither method
of redirection appears to be working? Is this considered a bug? I
spent a considerable amount of time trying to get this to work.

Also, how does one do a redirect to a different server if the to
parameter is appended to the end of the original URL? The examples
are really great, but they fail to demonstrate how to redirect to a
different server or application context.

If anyone has any experience with this I'd love to see a working
example of a full redirect and a redirect from a context path.

Thank you,
James


====== Message from April 11, 2009 =======

Hi all,

This is a great tool and I can't believe I've done without it for so
long.

I did find one bug in the 2.6 version. This rule:

<rule>
<condition name="host">^aapgppv\.ftoth.*$</condition>
<condition type="request-uri" operator="notequal">^/data/
open/.*
$</condition>
<from>.*</from>
<to type="redirect">/data/open/ppv.do</to>
</rule>

failed in an odd way. The conditions would match properly, but the
redirect would
actually double the string, like this: "/data/open/ppv.do/data/open/
ppv.do".

For some reason, changing the <from> rule to this (adding the ^ and $)
fixed it:

<from>^.*$</from>

Thought you should know.

Thanks,

Fred

Wim De Smet

unread,
Jan 12, 2011, 3:52:27 AM1/12/11
to urlre...@googlegroups.com
Hi,

On Wed, Jan 12, 2011 at 12:17 AM, James M <jmor...@gmail.com> wrote:
>    <rule>
>        <note>
>            redirect
>        </note>
>        <from>/*</from>
>        <to type="redirect">/abc</to>
>    </rule>

> [...]


> Browsing to http://mydomain.com/new redirects to http://mydomain/abc/abc.
> Why does it double up on the path?

I had a look. I'm 99% sure it's a bug. Just a note, you're not
matching what you probably think you're matching here. Since this is a
regex you're matching the empty string or any succession of /-es. For
some reason, this triggers a bug somewhere. What does work is stuff
like:
<from>/.*</from>
or
<from>^/$</from>
or even:
<from>^/*$</from>

Which is Fred's workaround mentioned below, but the anchors shouldn't
really be making a difference.

> Also, how does one do a redirect to a different server if the to
> parameter is appended to the end of the original URL?  The examples
> are really great, but they fail to demonstrate how to redirect to a
> different server or application context.

In principle it should work exactly like
HttpServletResponse.sendRedirect[1]. Note that you can also send a
permanent redirect (type="permanent-redirect"), which is usually the
more logical choice when sending cross-domain redirects.

[1]:http://download.oracle.com/javaee/5/api/javax/servlet/http/HttpServletResponse.html#sendRedirect(java.lang.String)

> If anyone has any experience with this I'd love to see a working
> example of a full redirect and a redirect from a context path.

The from rules I listed above work for your example. They should also
work if you enter an absolute URL. I'm not sure what else you are
missing?

cheers,
Wim

Reply all
Reply to author
Forward
0 new messages