.htaccess - Basic authentication for subsite only -
i have single site, want protect. it's /phpinfo
on website.
there several redirects. apache file looks this:
rewriteengine on ... list of rewriterules rewriterule ^(phpinfo)$ index.php?controller=$1
index.php takes controller argument , includes specific site viewed.
i use basic authentication on several places already, works fine:
authuserfile /var/www/....../.htpasswd authgroupfile /dev/null authname "protected content" authtype basic <limit get> require valid-user </limit>
but, question is how can limit basic authentication /phpinfo
on server, site protected? ideally authuserfile
points relative directory can deploy on live server without needing change path.
a solution using php , not htaccess. it's simple yet effective.
if (!isset($_server['php_auth_user']) || $_server['php_auth_user'] != config::adminuser || $_server['php_auth_pw'] != config::adminpassword) { header('www-authenticate: basic realm="protected content"'); header('http/1.0 401 unauthorized'); die('protected content'); }