title: Tomcat Rewrite Valve - How to Keep Pretty URL on Client Browser
body: <p>I'm using Tomcat <strong>Rewrite Valve API</strong> so that I could publish my webapp URLs as '<em>pretty URL</em>'. My issue is that after successful URL rewriting, the browser url address did not keep the pretty URL, but display to the final ugly URL that I tried to hide in the first place, therefore defeating the purpose of using this nice API. I understand with Apache <strong>mod_rewrite module</strong>, the browser would keep the pretty URL that user enters after the successful rewrite; hence hiding nitty-gritty URI and params from naked eyes. Is it possible to achieve this with Rewrite Valve API? How?</p>
  
  <p>Configs</p>
  
  <ol>
  <li><p>Server = Tomcat Apache 9.0.30</p></li>
  <li><p>[webapp]/META-INF/<strong>context.xml</strong></p></li>
  </ol>
  
  <p><code>&lt;Context override="true" &gt;
      &lt;Valve className="org.apache.catalina.valves.rewrite.RewriteValve" /&gt;
  &lt;/Context&gt;</code></p>
  
  <ol start="3">
  <li><p>[webapp]/WEB-INF/<strong>rewrite.config</strong></p>
  
  <p><code>RewriteRule ^/support/contactUs/?$ ?page=page_supportID&amp;fragment=fragment_contactUsID [NC,L]</code></p></li>
  </ol>
  
  <p><strong>Use-Case</strong>: User enters on their browser pretty URL: <code>http://example.com/support/contactUs</code></p>
  
  <p><strong>Expected</strong>: The rewrite rule applies and opens the actual (ugly) URL = <code>http://example.com?page=page_supportID&amp;fragment=fragment_contactUsID</code>, and user browser still displays pretty URL = <code>http://example.com/support/contactUs</code>.</p>
  
  <p><strong>Actual</strong>: The rewrite rule applied and opened the actual (ugly) URL = <code>http://example.com?page=page_supportID&amp;fragment=fragment_contactUsID</code>. HOWEVER the browser url address also displayed that ugly url to user, instead of keeping the pretty one.</p>