title: RewriteRule to redirect to subdirectory based on HTTP_REFERER
body: <p>I have a problem where a wordpress install was moved from <code>/</code> (root) to <code>/beta/</code> (subdirectory).  I have it working great, except that there are some page links that are linking to, for instance, <code>/my-page</code> which is now a 404, and I want it to redirect to <code>/beta/my-page</code>.  These links <em>exist</em> on <code>/beta/(.*)</code> paths, so my thought was to make a <code>.htaccess</code> rule in the main root path that would see that a link came from <code>/beta/*</code> and simply redirect the user back to the proper page.  This is what I have so far:</p>
  
  <pre><code>RewriteEngine On
  # `HTTP_REFERER` contains my beta path...
  RewriteCond %{HTTP_REFERER} /march\-beta
  # The current page is not *already* a `/march-beta` page (don't want an infinite redirect)
  RewriteCond %{REQUEST_URI} !/march\-beta
  # Remap the entire path to be in the correct subdirectory
  RewriteRule ^(.*)$ /march-beta$1 [R=302, L]
  </code></pre>
  
  <p>However... I'm getting a 500 server misconfiguration kind of error when I save the file in the webroot of the server.</p>
  
  <p>An example:</p>
  
  <p>If a user is on <code>/march-beta/t-shirts</code></p>
  
  <p>and clicks on a link that links to:  <code>/blue-t-shirts</code>  (or even <code>/t-shirts/blue-ones</code>)</p>
  
  <p>I want the <code>.htaccess</code> file to see that the <code>HTTP_REFERER</code> contains <code>/march-beta</code> and immediately <code>R=302</code> them to <code>/march-beta/blue-t-shirts</code> (or <code>/march-beta/t-shirts/blue-ones</code>, in the second case).</p>