.htaccess – Introduction

.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. These .htaccess files can be used to alter the configuration of the Apache Web Server software.

‘.htaccess’ is the filename in full, it is not a file extension. For instance, you would not create a file called, ‘file.htaccess’, it is simply called, ‘.htaccess’. This file will take effect when placed in any directory which is then in turn loaded via the Apache Web Server software. The file will take effect over the entire directory it is placed in and all files and subdirectories within the specified directory.

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


Some of the uses of .htaccess files are

  • Redirects
  • Password protection
  • Deny visitors by IP address
  • Disable directory listings
  • Setting server timezone
  • Preventing access to your PHP includes files
  • Prevent access to php.ini

The recent case where I used .htaccess is to add www. to my domain name. When a user enters a domain name, for example gad2.com, it automatically redirects to www.gad2.com.

In order to add a redirect code just add the following code and save it as .htaccess and place it in the server.

RewriteCond %{HTTP_HOST} ^gad2.com$
RewriteRule (.*) http://www.gad2.com/$1 [R=301,L]

This will redirect automatically to www.gad2.com. I will continue posting more on .htaccess in my following posts.

Thanks for reading

Follow me


Web Developer at Energy Alternatives India
I'm interested in developing Web applications andkeen on learning new technologies.

View Nagarajan's Profile
Follow me

Latest posts by Nagarajan (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *

займ на карту онлайн круглосуточно