What you are trying to do isn't going to be simple. You want HTTP Authentication for a single file but only when there's the mode=register
query string. The mod_auth directives simply can't handle something like that.
What you're going to need to do is create a new php file, one that includes the ucp.php
, we'll call that ucp_register.php
, and it just executes the ucp.php
file in the local file system, passing it the mode=register
query string. Then, we force authentication for ucp_register.php
.
<Files "ucp_register.php">
AuthUserFile /path/to/htpasswd
AuthName "Password Protected"
AuthType Basic
Require valid-user
</Files>
Then, we intercept requests for ucp.php
with the register mode, and internally rewrite that to ucp_register.php
, which requires a valid-user, which means the browser is prompted to authenticate, but the browser still thinks its requested ucp.php?mode=register
. After authentication, the ucp_register.php
file is loaded, which loads ucp.php
and does the registering. To do the rewrite, you need:
RewriteCond %{QUERY_STRING} mode=register
RewriteRule ^ucp\.php$ /ucp_register.php [L]
Probably some details that you'll need to work out to get this to work, but this is the general idea.
For example, the ucp_register.php
file could look something as simple as:
<?php
include('ucp.php');
?>