Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
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.


Back to the top