Apache .htaccess File

.htaccess file

  • The .htaccess file stands for hypertext access file.
  • It is a configuration file supported by several web servers.
  • The .htaccess file is used for configuration of site-access issues, like URL redirection, URL shortening, Access control security for different web pages and files.
  • It is not used when you have access to httpd.conf file.
  • It is used only when you don't have access to httpd.conf file.
  • The .htaccess file is known as “distributed configuration file”.
  • It helps in making configuration changes on a per-directory basis.
  • It is a simple text file placed in the directory which can control the access to your web site files.

Creating .htaccess file

  • This file is created using a "text editor" like notepad for WINDOWS and the “vi editor” for LINUX.
  • Put .htaccess file in the directory.
  • Example : .htaccess file

    AuthUserFile D : \dwnlds\SampleDir\ .htpasswd
    AuthType Basic
    AuthName “I WON”
    Require valid-user

    where,
         'AuthUserFile' directive tells the Apache web server where the username/password pairs are going to be stored.
         'Basic' is only type of authentication that is used.
         'AuthName' indicates the collection of documents that are to be protected.