Search code examples
.htaccess.htpasswd

htaccess - only index requires valid-user


I've got a simple htaccess set up with which I only want to protect my index.php file. I wrote down the following which seems the most logic, but it just tells me 401 Authorization Required. If I open up the link WITH index.php, it does prompt me for a login, otherwise not.

Is there any way I can trigger that login without adding index.php to the link? I really only want the index.php protected.

<Files index.php>
  require valid-user
</Files>

Thanks!


Solution

  • Try using LocationMatch:

    <LocationMatch "(.*/|index.php)$">
        Require valid-user
    </LocationMatch>