I want anyone to be able to read 'file.php' but I want to password protect the same file if the url is 'file.php?page=mypage'. I've tried htpasswd but it isn't working:
<FilesMatch "page.php?page=mypage">
AuthName "Secret page"
AuthType Basic
AuthUserFile /home/cowfart/public_html/.htpasswd
require valid-user
</FilesMatch>
What else could I do to make it work? By the way, this website is based around one file which gets variables from the url and echos other files depending on this variable
I don't think it is possible to htpasswd files depending on their URL parameters. I think the best way to go about password protecting a page like this is to code a login script, requiring a user to login to access the page.
eg.
<?php
if($_GET['page'] == "mypage")){
// Require login
}
?>