What is .htaccess File? An Introduction To htaccess Files
This article is an introduction part of the series of tutorial on .htaccess files. So what is .htaccess file? Why do we use .htaccess files? Similar questions may arise in your mind if you are related to web technologies or if you have newly entered to web world. So in this article I will give a brief explanation about the .htacces files and its usage in short. We can go in details about the usage of htaccess file in later part of this series. So lets get started.
What is .htaccess file?
Well full form of htaccess is “Hypertext Access” and the complete file name is “.htaccess” and it is not a file extension the name of the file itself starts with a dot. In real “.htaccess” file is a directory level configuration file supported by several web servers. That means “.htaccess” file contains some server level configuration settings which is applied to that particular directory where this file is residing. It actually decentralizes the management of web server configuration.
Often many people think that “.htaccess” file is only associated with apache webserver but many webservers are now supporting this htaccess file. The configuration present inside the file are applied to the whole directory and its sub directories. Format of the htaccess file is same as the Apache Web Server‘s Gloal configuration format. Below is an example of htaccess file configuration:
# This allows you to redirect index.html to a specific subfolder/URL
Redirect /index.html http://example.com/myurl/
The above example will redirect the request to the new URL http://example.com/myurl/. In this case the file has to be kept in the root directory of the sweb erver as we are redirecting the /index.html to some other url. This is just a small and simple example. There are lot many you can do with htaccess configuration.
You can create a .htaccess file using any standard text editor such as TextPad, Microsoft WordPad and similar but you cannot use Microsoft NotePad as it will not allow you to save it with a starting dot.
Advantage of .htaccess
Changes made in these files take immediate effect as .htaccess files are read on every request.You don’t need to restart the server.
Demerit Of .htaccess
For each HTTP request, there are additional file-system accesses for parent directories when using .htaccess, to check for possibly existing .htaccess files in those parent directories which are allowed to hold .htaccess files.
Allowing individual users to modify the configuration of a server can cause security concerns if not set up properly.
This is just an introduction to the htaccess files. In the next tutorials we will see lot more about different configuration option of htaccess.