I have an instance running on EC2 that I want to password protect.
my .htaccess file;
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} ^http$
RewriteCond %{REQUEST_URI} !^/healthcheck\.html$
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
AuthName "Restricted"
AuthUserFile /var/www/html/mydirectory/.htpasswd
Require valid-user
<Files "my_healthcheck_file.php">
Allow from all
Satisfy any
</Files>
.htpasswd is username:password for just now. As I am running ELB I have allowed all connections to my healthcheck file so the instance will be healthy and not blocked by password. I've needed to open this connection otherwise it returns 503 error.
I believe my problem lies with the AuthUserFile. however I have tried both /var/www/html/mydirectory/.htpasswd and the absolute path: /var/app/current/mydirectory/.htpasswd & both return error 500.
unsure what I am doing wrong, I have even checked the path is correct by doing:
<?php
$dir = dirname(__FILE__);
echo "<p>Full path to this dir: " . $dir . "</p>";
echo "<p>Full path to a .htpasswd file in this dir: " . $dir . "/.htpasswd" . "</p>";
?>
Any suggestions is much appreciated! Thanks!