title: .htaccess rewrite to directory based on cookie
body: <p>In my app I want to use <em>mod_rewrite</em> to have nice URLs, but also redirect logged in users (detected by <code>logged</code> cookie) to old not-so-nice URLs like this:</p>
  
  <p>Nice URL: <code>mydomain.com/topic/12-name/</code></p>
  
  <p>Not-so-nice URL: <code>mydomain.com/other_topic?item_id=12&amp;other=params</code></p>
  
  <p>My .htaccess</p>
  
  <pre><code>RewriteEngine on
  
  RewriteCond %{HTTP_COOKIE} logged
  RewriteRule ^topic/([0-9]+)-([a-zA-Z0-9_-]+)/$ /other_topic?item_id=$1&amp;other=params [R=301,L]
  
  RewriteRule ^topic/([0-9]+)-([a-zA-Z0-9_-]+)/$ /other_topic?item_id=$1&amp;other=params [NC,L]
  </code></pre>
  
  <p>First one - redirect - works perfectly fine. Second one - rewrite - doesn't work at all. Any thoughts why? </p>