Pages

Showing posts with label apache2. Show all posts
Showing posts with label apache2. Show all posts

Monday, September 21, 2015

htaccess apache2 authentication for specific directory

@@ Apache version 2.4 and above. @@

Create .htaccess file in /var/www/html directory and add following lines

********************************
AuthType Basic
AuthName "Password Required"
AuthUserFile /var/www/html/webmail/.htpasswd
AuthGroupFile /dev/null
Require user webmail

*******************************


Create another file for storing password and save it as blank file
vim /var/www/html/webmail/.htpasswd


Create & store password
htpasswd -m /var/www/html/webmail/.htpasswd webmail


Now enable a module with below command
a2enmod authz_groupfile

Restart apache2 service



Edit apache.conf file with below lines
AccessFileName .htaccess [remove hash (#) in front of this line]

Change below lines from
**********************************
<Directory /var/www>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

*********************************

to
*********************************
<Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

*********************************


Restart apache2 service and check now. It will prompt you for username and password.

Tuesday, March 24, 2015

Multiple page redirection from single Linux Server using Apache2

I have a Linux server with Apache2 as its web service. I want to redirect two sites pointed to that server to other two websites. At first I was confused how to do that as I work in networking section. Later I got help anyway and I am going to share the solution with you.

First I have to change default page 'index.html' to 'index.php'.


Then I have given below code to redirect those to two sites to another two websites.


##################################
<?php
 $actual_link = "$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

if($actual_link == "www.xyz.com/")
    $redirect_page = "http://www.anotherone.com/";
if($actual_link == "web2.xyz.com/")
    $redirect_page = http://www.anothertwo.com/;

?>
<html>
    <head>
        <meta http-equiv="refresh" content="3;url=<?php echo $redirect_page ?>" />
    </head>
    <body>
        <h1>Please wait, You are redirecting... </h1>
    </body>
</html>

#################################


I am happy with this simple solution. You??

Tuesday, November 15, 2011

htaccess (Apache Authentication)

Sometimes we may face problem with our webmail when the spam mails generated from it changing the from ID and from server itself (127.0.0.1).

In that case we may enforce a authentication to access our webmail. Lets see how we can do it.

Create a file:
vim /var/www/.htaccess


AuthType Basic
AuthName "Password Required"
AuthUserFile /var/www/webmail/.htpasswd
AuthGroupFile /dev/null
Require user test

Save and Exit.

Create another file:
vim /var/www/webmail/.htpasswd

Save and exit.

Edit the following file:
vim /etc/apache2/sites-available/default

Change AllowOverride None to AllowOverride All

Save and Exit.

Now create the password:
htpasswd -m /var/www/webmail/.htpasswd test

New password:
Re-type new password:

Now restart apache:
/etc/init.d/apache2 restart

Access your webmail address now.