Now we can use .htaccess file also for controlling the access that when instead of specifying
authentication directive in httpd.config.
What you can do, you can create .htaccess file in which directory /var/www/html/example1
directory that is going to control access to our example1.com site.
So in our case, we will go to /var/www/html/example1 directory.
And with cat command we are going to create .htaccess file and we are going to specify these four
lines AuthType Basic, AuthName Restricted Access, AuthUserFile /etc/httpd/webpasswd.
And then we are going to specify Require user anantika and nanu then with ls -a command, we are going
to view our pages that mean Index.html is our default homepage and this is the your access.
Then we can view that also.
But please, just creating this .htaccess file will not do anything.
We have to make one configurations changes in our httpd.config.
What that we have to do to make this file effective, we have to change the value of option, Allow
Override from None to AuthConfig in configuration file httpd.config that mean we will be creating .htaccess
file also.
But to be effective what we need, we will go into our httpd.config file and we will create one
Directory directive regarding /var/www/html/example1.
And we are going to say AllowOverride AuthConfig.
That mean we are saying that please allow the setting of that which are in .ht
access.
file to be implemented and then you just check that configuration.
if It will show syntax is ok, reload http server.
And please remember, we only want to override this directory settings regarding your configuration
setting.
So please do not change this, Directory /.
where by default.
One option is there AllowOverride.
none Require all denied.
That means by default security that /directory otherwise your system will become vulnerable.
So you have to only make changes in which this /var/www/html/example1 because
we want to control the access to our example1.com only.
So let us we are going to see the demo of that also.