title: Apache mod_rewrite encoded URLs
body: <p>I'm working on a webpage that takes a URL as a parameter, and would like it to be easily indexed by search engines.  One requirement is that each URL appears as a directory.</p>
  
  <p>My script is in the format:</p>
  
  <pre><code>myscript?url=&lt;a url&gt;&amp;page=1
  </code></pre>
  
  <p>I'd like redirects to look something like:</p>
  
  <pre><code>lookup/&lt;a url&gt;/page:1/
  </code></pre>
  
  <p>The URL is predictably giving me trouble... I just want to tell mod_rewrite to select <em>anything</em> after "lookup/" and before "/page:".  Of course, nothing is ever as simple as it could be.</p>
  
  <p>Here's the rewrite as it is now:</p>
  
  <pre><code>RewriteEngine on
  RewriteRule ^/lookup/(.+)/page:([0-9]+)(/?)$ /myscript?url=$1&amp;page=$2 [L]
  </code></pre>
  
  <p>This works great, except it fails when URLs are properly encoded.  Take the example of "www.google.com/finance".  Here's what happens when I enter these URLs into my browser's address bar:</p>
  
  <pre><code>#this works
  lookup/www.google.com/finance/page:1/
  
  #this doesn't work.  url is cut off before the ?
  lookup/www.google.com/finance?foo=bar/page:1/
  
  #doesn't match rewrite at all!
  lookup/www.google.com%2Ffinance/page:1/
  </code></pre>
  
  <p>I'm at a loss as to how to do this... Shouldn't (.+) select <em>anything</em>?  Do I need to tell mod_rewrite to ignore query parameters somehow?</p>