Here is a quick and easy to understand guide on What is .htaccess file? so that you can quickly get on wheels and start exploring furthermore just by understanding the concept in short.
Before understanding What is .htaccess file?
Basically you can modify apache web server configurations at the core of apache’s main server config file i.e. inside httpd.conf file for Windows & Linux based OS (CentOS) or apache2.conf file for Ubuntu.
But if you don’t have access to these core files at the web-server level or if you don’t want to restart the web-server (on every change in these core files, web-server has to be restarted), that is where .htaccess file comes into play.
What is .htaccess file?
.htaccess files provides a way to make configuration changes on a per-directory basis.
Rohutech‘s simplified interpretation
If you ever want to modify or set access rules on any directory of your website, you can do so by using the .htaccess file.
This can be done by creating .htaccess file at any directory level, it is mostly done at the root directory of the website i.e. from where the webserver loads the website (inside public_html or www folder ) so that you can control the access of the whole website.
If at all you want to manage the access at any other sub-directory level you can still do so by creating another .htaccess in the required subdirectory.
Why do we use it?
If you ever want to do any of the following or even more:
- Redirect your website
- Set a maintenance page
- Set a header variable which needs to be supplied to the website in every single request
- Create custom error pages like
- 403 Forbidden Page
- 404 File not Found
- 500 Internal Error
- Similarly, there are so many applications you can use .htaccess file for
Things to consider before using .htaccess file
One should always avoid using .htaccess files completely if one has access to the main server config file which is httpd.conf or apache2.conf file. .htaccess files will always slow down the Apache HTTP server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance.
Since .htaccess file is available at the directory level of the website it is much more accessible than standard apache configuration file httpd.conf. Therefore there are more chances of any illegal access to .htaccess file than actually having access to httpd.conf which is stored at OS program files.
When is .htaccess file allowed to execute
AllowOverride is one of the directives of the apache core feature which is responsible for executing .htaccess file. When this directive is set to “All”, only then the access control rules in .htaccess file are taken into consideration or else they are completely ignored.
To make .htaccess to execute
In httpd.conf find for <Directory> sections which have AllowOverride None and change it to AllowOverride All
That’s all, Hope you guys got some idea about What .htaccess file is all about. Don’t forget to Like, Share & Comment.
Also, Have a look at some of the top reads of Rohutech