Thank you very much Alexei! Regex lookarounds are something
I have trouble with.  Did you do this off
the top of your head? It worked perfectly, but I am trying to figure out how to
debug this, so that I learn from all this.
 
            My first
problem is that after getting your suggestion to work i.e. enabling 

OPTIONS=rewrite
etc/jetty-rewrite.xml
in my start.ini and putting your suggestion into
jetty-rewrite.xml, I decided to comment out the new rule from
jetty-rewrite.xml. I have no other rules at this time, but I am running Solr on
this jetty instance. When I attempt to access / i.e. http://localhost:7070/ I 
get a 500 error, not
a 404 error that I expected and I get the following exception in my log file.
 
1412 [main] INFO  org.apache.solr.servlet.SolrDispatchFilter  -
user.dir=C:\Users\<<MyUserName>>\Documents\Jetty\NewJetty9
1412 [main] INFO  org.apache.solr.servlet.SolrDispatchFilter  - 
SolrDispatchFilter.init() done
2013-06-06 11:14:31.008:INFO:oejsh.ContextHandler:main:
Started
o.e.j.w.WebAppContext@41d12299{/solr,file:/C:/Users/<<MyUserName>>/AppData/Local/Temp/jetty-0.0.0.0-7070-solr.war-_solr-any-/webapp/,AVAILABLE}{C:\Users\<<MyUserName>>\Documents\Jetty\NewJetty9\webapps\solr.war}
2013-06-06 11:14:31.075:INFO:oejs.ServerConnector:main:
Started ServerConnector@48ee6315{HTTP/1.1}{0.0.0.0:7070}
2013-06-06 11:14:31.207:WARN:oejs.HttpChannel:qtp1881283994-32:
/
java.lang.NullPointerException
            at
org.eclipse.jetty.rewrite.handler.RuleContainer.apply(RuleContainer.java:199)
            at
org.eclipse.jetty.rewrite.handler.RuleContainer.matchAndApply(RuleContainer.java:186)
            at
org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:313)
            at
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
            at
org.eclipse.jetty.server.Server.handle(Server.java:445)
            at
org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:260)
            at
org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:225)
            at
org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
            at
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:596)
            at
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:527)
            at
java.lang.Thread.run(Unknown Source)
 
Just to make sure, I restored jetty-rewrite.xml from the
original download and I still get this exception. However, if I disable i.e.
comment out the two lines mentioned above in the start.ini, then I correctly
get the expected 404. Why does this happen?
 
            I also
attempted to modify your suggestion to make rewrite possible from 
http://localhost:7070/foo/bar to http://localhost:7070/solr/#/foo/bar (I’m just 
playing here). I tried the following: 
 
<Call name="addRule">
  <Arg>
    <New
class="org.eclipse.jetty.rewrite.handler.RewriteRegexRule">
      <Set
name="regex">(^(?!/solr/#/).*)</Set>
      <Set
name="replacement">/solr/#$1</Set>
    </New>
  </Arg>
</Call>
 
This did not work. Do I need to escape the # ? I didn’t
think # is a special character in regex.
 
Thank you for all the help.
O. O. 


----- Mensaje original -----
De: Alexei Mikhailov <[email protected]>
Para: [email protected]
CC: 
Enviado: Jueves, 6 de junio, 2013 1:59 A.M.
Asunto: Re: [jetty-users] Jetty 9 Redirect from Root to Sub-Directory.

Hi there,

On 6/5/13 23:08, O. Olson wrote:
> 
> Perfect Joakim! Thank you very much.
>   Could someone please show me how to edit the
> jetty-rewrite.xml to rewrite from http://localhost:7070/ to 
> http://localhost:7070/solr/
>  
It somewhat depends on what effect you want to achieve. I would assume you want 
http://localhost:7070/foo/bar be redirected to 
http://localhost:7070/solr/foo/bar?
In this case, regex would be something like:

<Call name="addRule">
  <Arg>
    <New class="org.eclipse.jetty.rewrite.handler.RewriteRegexRule">
      <Set name="regex">(^(?!/solr/).*)</Set>
      <Set name="replacement">/solr$1</Set>
    </New>
  </Arg>
</Call>

Here, regex matches any characters after root context, (excluding "/solr/", 
since that's where you want your redirect to go), and groups them so we can 
reference those in "replacement". It's not the most elegant regex, but at least 
it's (somewhat) readable.

Hope that helps,
Alex-


> As mentioned in my original post I looked at 
> http://www.eclipse.org/jetty/documentation/current/jetty-handlers.html#rewrite-handler.
> Is this the correct way to add the rewrite rule? (I have absolutely no clue,
> but someone suggested this online.)
>   <!-- Newly added to rewrite from root to slor -->
>               <Call name="addRule">
>          <Arg>
>            <New
> class="org.eclipse.jetty.rewrite.handler.RewriteRegexRule">
>              <Set
> name="regex">^$</Set>
>              <Set
> name="replacement">/solr/</Set>
>            </New>
>          </Arg>
>        </Call>
>   Thank you again,
> O. O.
_______________________________________________
jetty-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/jetty-users

_______________________________________________
jetty-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/jetty-users

Reply via email to