title: HTTPS redirect for directory doesn't work correctly
body: <p>My goal is to force HTTPS on the <code>admin</code> directory of my site. However, using the usual way give an unusual result. Here is the content of <code>.htaccess</code>:</p>
  
  <pre><code>RewriteEngine On 
  RewriteCond %{SERVER_PORT} 80 
  RewriteCond %{REQUEST_URI} admin
  RewriteRule ^(.*)$ https://www.domain.com/admin/$1 [R,L]
  </code></pre>
  
  <p>However, when I try to open <code>http://www.domain.com/admin/home.php</code>, instead of redirecting to <code>https://www.domain.com/admin/home.php</code> it sends me to <code>https://www.domain.com/admin/admin/home.php</code>.</p>
  
  <p>So it sort of creates the <code>admin/</code> part of the URL twice.</p>
  
  <p>I tried changing the last line of <code>.htaccess</code> to <code>RewriteRule ^(.*)$ https://www.domain.com/$1 [R,L]</code> (which doesn't make sense to me, but tried it still) and it redirected to the same wrong URL, which confused me further.</p>
  
  <p>I'm not sure if it should matter, but I've also tried replacing <code>[R,L]</code> with <code>[L,R=301]</code> as suggested elsewhere on SO, with no avail.</p>
  
  <p>Why is this happening and what's the solution?</p>