title: mod_rewrite send everything not matched to a rewritemap
body: <p>I have an htaccess file which begins with the regular stuff:</p>
  
  <pre><code>RewriteEngine on
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  </code></pre>
  
  <p>then has a few rewrites eg:</p>
  
  <pre><code>RewriteRule ^protect/?$ /Legal/Your-Financial-Protection.aspx   [NC, L, R=301]
  </code></pre>
  
  <p>then ends with a rewritemap:</p>
  
  <pre><code>RewriteMap map txt:rewritemaps/map.txt  [NC]
  RewriteRule ^(.+)$  ${map:$1}   [R=301]
  </code></pre>
  
  <p>The rewritemap contains all of our legacy urls - pages on our current site and short urls that will be redirected to equivalent pages on the new site (there are about 4k, so I need to use a map really):</p>
  
  <pre><code>Inspiration.aspx /Inspiration.aspx
  Destinations/Africa/Countries/Gabon.aspx /Destinations/Africa/Gabon.aspx
  indonesia /Destinations/Southeast-Asia/Indonesia.aspx
  </code></pre>
  
  <p>The problem is, with the rewritemap enabled (ie not commented out), all my urls (even those not matched) redirect to / - including stylesheets, js, images etc.</p>
  
  <p>What I'm after is uris that match the pattern in the map to redirect to the replacement and everything else to pass through (ie stay the same).</p>
  
  <p>I've tried setting a default of $1 on the map:</p>
  
  <pre><code>RewriteRule ^(.+)$  ${map:$1|$1}    [R=301]
  </code></pre>
  
  <p>but this just causes a redirect loop. I think I could also skip rewriting for all .css, .js, .jpg etc but would rather not have to maintain a list of used file extensions.</p>
  
  <p>FYI, I'm using ISAPIRewrite from HeliconTech (as I'm on IIS 6) although it claims to handle rewritemaps as per apache and we've never had problems in the past.</p>
  
  <p>Any help would be hugely appreciated!</p>
  
  <p>Thanks, Adam</p>