title: How to rewrite outbound links in mod_rewrite?
body: <p>I can't find an answer to this looking at the beginners guide on the net. If someone could please help me out I'd be very thankful.</p>
  
  <p>All I want to do is rewrite links (which exist in <code>&lt;a href&gt;</code> tags) on my page that look like this:</p>
  
  <pre><code>&lt;a href="/mysite/products/product.cfm?id=1"&gt;/mysite/products/product.cfm?id=1&lt;/a&gt;
  </code></pre>
  
  <p>into this:</p>
  
  <pre><code>&lt;a href="/mysite/products/product/1"&gt;/mysite/products/product/1&lt;/a&gt;
  </code></pre>
  
  <p>All the examples that I can find on the net are about inbound rewriting rules e.g. resolving a friendly-URL into a real URL. </p>
  
  <p>But how do I turn a real URL into a fake URL on my page on the fly? I'm using Helicon Ape which is basically Apache mod_rewrite within IIS 7.5. I still have to put all my rules in .htaccess</p>
  
  <p>If I use IIS URL Rewrite Module from Microsoft, then it allows you to create "Outbound" rules which rewrites links within your HTML markup on the fly. Here is an example of an Outbound rule:</p>
  
  <pre><code>&lt;rule name="Rewrite to clean URL" preCondition="IsHTML"&gt;
  &lt;match filterByTags="A" pattern="^/article\.aspx\?id=([0-9]+)$" /&gt;
  &lt;action type="Rewrite" value="/article/{R:1}" /&gt;
  &lt;/rule&gt;
  </code></pre>
  
  <p>So it rewrite any link in an <code>&lt;a&gt;</code> tag that looks like <code>/article.aspx?id=1</code> and makes it into <code>/article/1</code></p>