[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[jetty-users] Unexpected behaviour with basic RewriteRegexRule
|
Hi everyone. I'm having trouble using org.eclipse.jetty.rewrite.handler.RewriteRegexRule from within jetty-rewrite.xml. My needs are very simple:
* Internally rewrite all URLs matching /foo/(.*) to a WAR named $1 in webapps.
* Make the original untranslated URL available to the WAR in getPathInfo().
For instance, if the URL is /foo/bar, that should internally redirect to a webapp named bar.war (ie. /bar). Similarly, /foo/bar/baz should redirect to /bar/baz and be picked up by bar.war. Ideally, I would set up Jetty so that all WARs inside a specific directory are accessed from /foo. Is that possible?
My URL redirection requirements are really basic, but I can't get even this to work. I must be missing something. I can do it using mod_rewrite in Apache, but I don't want to introduce that extra dependency. Searching the web, I'm not the only one who has this issue but I can't find any solutions.
I'm using jetty-hightide-7.2.1.v20101111 on Mac OS Snow Leopard (should that make a difference).
You can find my etc/jetty-rewrite.xml below. Here's what happens:
* http://localhost:8080/bar brings up the webapp at bar.war just fine.
* http://localhost:8080/foo/bar => HTTP 404 (Jetty style)
* http://localhost:8080/foo => HTTP 404 (Jetty style)
* http://localhost:8080/foo/ => contents of webapps/root/index.html
* http://localhost:8080/foo/a => contents of webapps/root/index.html
* Indeed, any single letter after /foo/ brings up webapps/root/index.html. Anything else brings up HTTP 404
If I change replacement to "/$1", all the above exhibit the same behaviour except:
* http://localhost:8080/foo/bar => HTTP 302 to http://localhost:8080/bar/
* http://localhost:8080/foo/a => HTTP 404 (Jetty style)
This is great, except that I don't want HTTP 302 as that's not an internal redirect as advertised.
If I switch to RedirectRegexRule without the leading slash in replacement, then:
* http://localhost:8080/foo => HTTP 404 (Jetty style)
* anything starting with http://localhost:8080/foo/ results in a redirection loop to the same URL
Introducing the slash with RedirectRegexRule redirects with HTTP 302 as expected.
Any help would be appreciated. Thanks.
Ian.
My etc/jetty-rewrite.xml:
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Get id="oldhandler" name="handler"/>
<Set name="handler">
<New id="Rewrite" class="org.eclipse.jetty.rewrite.handler.RewriteHandler">
<Set name="handler"><Ref id="oldhandler"/></Set>
<Set name="rewriteRequestURI">true</Set>
<Set name="rewritePathInfo">false</Set>
<Set name="originalPathAttribute">requestedPath</Set>
<Call name="addRule">
<Arg>
<New class="org.eclipse.jetty.rewrite.handler.RewriteRegexRule">
<Set name="regex">/foo/(.*)</Set>
<Set name="replacement">$1</Set>
</New>
</Arg>
</Call>
</New>
</Set>
</Configure>