title: Order of Jetty rewrite rules
body: <p>I'm working with some simple Jetty rewrite rules</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Configure id="FileServer" class="org.eclipse.jetty.server.Server"&gt;
      &lt;Get id="oldhandler" name="handler"/&gt;
      &lt;Set name="handler"&gt;
          &lt;New id="Rewrite" class="org.eclipse.jetty.rewrite.handler.RewriteHandler"&gt;
              &lt;Set name="handler"&gt;&lt;Ref id="oldhandler"/&gt;&lt;/Set&gt;
  
              &lt;Call name="addRule"&gt;
                  &lt;Arg&gt;
                    &lt;New class="org.eclipse.jetty.rewrite.handler.RewriteRegexRule"&gt;
                      &lt;Set name="regex"&gt;/fake-uri/(.*)&lt;/Set&gt;
                      &lt;Set name="replacement"&gt;/real-uri/$1&lt;/Set&gt;
                    &lt;/New&gt;
                  &lt;/Arg&gt;
              &lt;/Call&gt;
  
              &lt;Call name="addRule"&gt;
                  &lt;Arg&gt;
                      &lt;New class="org.eclipse.jetty.rewrite.handler.HeaderPatternRule"&gt;
                          &lt;Set name="pattern"&gt;/real-uri/*&lt;/Set&gt;
                          &lt;Set name="name"&gt;Cache-Control&lt;/Set&gt;
                          &lt;Set name="value"&gt;no-cache,no-store&lt;/Set&gt;
                      &lt;/New&gt;
                  &lt;/Arg&gt;
              &lt;/Call&gt;
  
          &lt;/New&gt;
      &lt;/Set&gt;
  &lt;/Configure&gt;
  </code></pre>
  
  <p>If I request <code>/fake-uri/index.html</code> in the browser, the response contains what would be served by <code>/real-uri/index.html</code> <em>and</em> applies the <em>Cache-Control</em> headers. However, if I reorder the rules so the header rule is above the regex rule, the <em>Cache-Control</em> headers are absent for requests to <code>/fake-uri/index.html</code>.</p>
  
  <p>Seems like order is important here, but I'm trying to workout what's happening. According to <a href="http://download.eclipse.org/jetty/7.6.13.v20130916/apidocs/org/eclipse/jetty/rewrite/handler/RewriteHandler.html" rel="nofollow">the doc</a></p>
  
  <blockquote>
    <p>HeaderPatternRule - adds/modifies the HTTP headers in response</p>
  </blockquote>
  
  <p>I'm unsure what the default is, but I've tried</p>
  
  <pre><code>&lt;Set name="rewriteRequestURI"&gt;true&lt;/Set&gt;
  </code></pre>
  
  <p>on the handler.</p>
  
  <p>It doesn't seem to change anything, but I'd think if the <strong>request</strong> URI were rewritten, it wouldn't matter where the URI rewrite rule appeared in relation to a header rewrite which applies to <strong>output</strong> headers. Thing is even with <em>rewriteRequestURI</em> set to <em>true</em>, the header rule has to come second for the desired effect. So why is order important when I've set <em>rewriteRequestURI</em>?</p>