title: apache: basic authentication before rewrite
body: <p>I have an Apache in frontend that should redirect a request via a <code>RewriteRule</code>.</p>
  <p>I have to put a basic authentication before the request is redirected, so I put this in the config file:</p>
  <pre><code>&lt;VirtualHost *:443&gt;
      ServerAdmin xxxxxx
      DocumentRoot /var/www/html/
      ServerName xxxxxxx
      RewriteEngine on
      ErrorLog logs/error.log
      CustomLog logs/access_log common
  
      &lt;Directory /var/www/html/&gt;
          AuthType Basic
          AuthName &quot;Restricted Files&quot;
          AuthUserFile /etc/httpd/conf/tag.pwd
          Require valid-user
          RewriteRule ^/(.*) http://xxxxxx:xxx/$1   [P,L]
      &lt;/Directory&gt;
  &lt;/VirtualHost&gt;
  </code></pre>
  <p>But it doesn't work.</p>
  <p>Any suggestions?</p>
  <p><strong>UPDATE:</strong> I would expect that all requests after authentication would be redirected with the rule <code>RewriteRule ^/(.*) xxxxxx:xxx/$1 [P,L]</code> but this doesn't happen. Apache search the page under <code>/var/www/html</code></p>