Beginning Htaccess Programming


What is .htaccess?

.htaccess is a configuration file for use on web servers running the Apache Web Server software. When a .htaccess file is placed in a directory which is in turn ‘loaded via the Apache Web Server’, then the .htaccess file is detected and executed by the Apache Web Server software. For a shared host, common configurations are same from this ‘httpd.conf’, but requirements may vary from user to user. These htaccess files help users fulfill their own requirements. It can also be referred as directory level configuration file. Because we can use this file on any number of directories we like and use different configuration settings for each of them.

How to use .htaccess

You can create a .htaccess file using any good text editor such as TextPad, UltraEdit, Microsoft WordPad and similar (you cannot use Microsoft NotePad).

Here is an example of what you might include in a .htaccess file.

If your .htaccess file does not work, you should contact your system administrator or web hosting company and ensure they have enabled .htaccess within your account. Some web hosting companies do not allow use without permission. If errors persist, consult this article for advice, or contact your system administrator for advice.

Basic Htaccess File Structures

Error documents

To set-up custom error documents, create a .htaccess file following the main instructions and guidance which includes the following text:

Authorization using Password protection

The password protection and authentication systems offered by the Apache Web Server are probably the most important use of .htaccess files.

create a .htpasswd file and paste the below code

Note : It is not possible to offer a log-out facility, the login details are cached in the web browser until the browser is closed, so visitors may leave the web site and return later in the session without being prompted to login again. When the browser is closed and re-opened the login details are deleted from the cache and the pop-up prompt will be displayed.

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:

Article Tags: ,