Issue
I have Apache httpd installed on my CentOS 7. By adding the following code in httpd.conf, I can password protect my website
<Directory /var/www/html>
AuthType Basic
AuthName "Restricted Files"
AuthBasicProvider file
AuthUserFile /var/www/password/htpasswd
Require user validUser
<Files index.php>
Require all granted
</Files>
</Directory>
Since I want to have /var/www/html/index.php not password protected, Require all granted
is added as shown. This, however, still requires me username and password. Please help, thanks ^^
Solution
Don't protect the complete directory but protect using a LocationMatch:
<LocationMatch "^/(?!index\.php).|index\.php.+$">
AuthType Basic
AuthName "Restricted Files"
AuthBasicProvider file
AuthUserFile /var/www/password/htpasswd
Require user validUser
</LocationMatch>
Answered By - Matthias Wimmer Answer Checked By - David Goodson (WPSolving Volunteer)