I am running apache2 and php5 in my windows PC.
I have protected my directory using .htaccess
and.htpasswd
. If login information is not set
Answer explanation :
You need to implement a custom authentication, natively you can not redirect on authentication fail.
Solution :
A custom ErrorDocument implementation using an HTML meta tag to make the redirection possible on authentication fail and let the user access the protected area on authentication success (The server will always cast out a 401 on first load before entering the user and password because the browser is not expecting such authentication in the first place and get refused the access)
AuthUserFile /path/to/users
AuthName "Access Denied"
AuthGroupFile /dev/null
AuthType Basic
Require valid-user
ErrorDocument 401 ""
Alternative I :
Since Apache 2.4. you can use mod_auth_form
with htaccess to make an advanced authentication and use a more reliable solution
http://httpd.apache.org/docs/trunk/mod/mod_auth_form.html
Alternative II :
Use a php to handle 401 ErrorDocument 401 /handle.php
http://php.net/manual/en/features.http-auth.php
Extended Security :
ErrorDocument 401 ""
ErrorDocument 400 /kickout.php
ErrorDocument 403 /kickout.php
ErrorDocument 500 /kickout.php
Deny from all
Allow from 192.200.x.x
Allow from 192.200.x.x
Allow from 127.0.0.1
Allow from localhost