title: strange 401 error appears for some urls when using .htaccess to redirect http to https
body: <p>OK, here is the 7th day of unsuccessfull attempt to find an answer why 401 error appears...</p>
  
  <p>Now, 
  .htaccess in the root folder contains the only 3 strings (was simplified) and there are NO more .htaccess files in the project:</p>
  
  <pre><code>RewriteEngine On
  RewriteCond %{HTTPS} !on
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  </code></pre>
  
  <p>So, it redirects all requests to be https. It works fine for any urls, even for /administration directory.</p>
  
  <p>So, </p>
  
  <pre><code>http://mydomain.com
  </code></pre>
  
  <p>becomes </p>
  
  <pre><code>https://mydomain.com
  </code></pre>
  
  <p>If <code>https://mydomain.com</code> was entered, there are no redirections.</p>
  
  <pre><code>http://mydomain.com/administration/index.php
  </code></pre>
  
  <p>becomes</p>
  
  <pre><code>https://mydomain.com/administration/index.php
  </code></pre>
  
  <p>If <code>https://mydomain.com/administration/index.php</code> was entered, there are no redirections.</p>
  
  <p>That's clear, and the problem is below.</p>
  
  <p>I want /administration directory to be password protected. My Shared Hosting Control Panel allows to protect directories without manual creating of .htaccess and .htpasswd (you choose a directory to protect, create username and password, and .htaccess and .htpasswd are created automatically). So, .htaccess appears in the /administration folder. .htpasswd appears somewhere else, the path to .htpasswd is correct, and everything looks correct (it works the same way as to create it manually). So, there are 2 .htaccess files in the project, one in the root directory and one in the /administration directory (with .htpasswd at the directory .htaccess knows where it is).</p>
  
  <p>Once the password is created,
  the results are:</p>
  
  <p>You enter:</p>
  
  <pre><code>https://mydomain.com/administration/index.php
  </code></pre>
  
  <p>Then it asks to enter a password.
  If you enter it correctly, 
  <code>https://mydomain.com/administration/index.php</code> is displayed.
  <strong>The result: works perfect.</strong></p>
  
  <p><strong>But, if you enter</strong> 
  <code>http://mydomain.com/administration/index.php</code> (yes, http, without S)
  then instead of redirecting to the same,but https page,
  it redirects to </p>
  
  <pre><code>https://mydomain.com/401.shtml (starts with httpS)
  </code></pre>
  
  <p>by unknown reason and even does NOT ask a password. <strong>Why?</strong></p>
  
  <p>I've contacted a customer support regarding this question and they are sure the problem is in .htaccess file, and they do not fix .htaccess files (that's clear, they do not, I don't mind).</p>
  
  <p>Why does this happen?
  Did I forget to put some flags, or some options to change default settings in the .htaccess file?</p>
  
  <p>P.S.Creating .htaccess and .htpasswd manually (not from hosting Control Panel) for the folder /administration causes the same 401 error in case if not https, but http was entered.</p>
  
  <p>And the problem appears with URLs to /administration directory only.</p>
  
  <p>Thank you.</p>