title: .htaccess rewrite rules that include a sub-folder
body: <p>Here is what I'm trying to do.</p>
  
  <p>I have 2 apps running on my site one at root <code>/</code> and one at at <code>/blog/</code>.</p>
  
  <p>I want to be able to access some pages that are served by the blog app but without the /blog/ part in the URL. This bit I have managed to do with the following rule.</p>
  
  <pre><code>RewriteRule my-page blog/index\.php?page_id=1 [L]
  </code></pre>
  
  <p>This allows me to view a page actually at <code>/blog/my-page</code> at <code>/my-page</code>.</p>
  
  <p>Now where I'm struggling is with ensuring there are no duplicate URLs, so I'm trying to redirect to my shorter URL. Like so:</p>
  
  <p>From:</p>
  
  <pre><code>/blog/my-page
  </code></pre>
  
  <p>To:</p>
  
  <pre><code>/my-page
  </code></pre>
  
  <p>From:</p>
  
  <pre><code>/blog/index.php?page_id=1
  </code></pre>
  
  <p>To:</p>
  
  <pre><code>/my-page
  </code></pre>
  
  <p>With the following rule, I can redirect from <code>/index.php?page_id=1</code> to <code>/my-page</code></p>
  
  <pre><code>RewriteCond %{QUERY_STRING} ^page_id=1$
  RewriteRule index\.php$ my-page? [R=301,L]
  </code></pre>
  
  <p>After this rule happens the first rule I mentioned takes it to the right place.</p>
  
  <h2>My question is:</h2>
  
  <p>How can I get it to work with <code>blog</code> as part of the URL. I expected the below to work but it doesn't</p>
  
  <pre><code>#RewriteCond %{QUERY_STRING} ^page_id=1$
  RewriteRule ^blog/index\.php$ my-page? [R=301,L]
  </code></pre>