.htaccess file stands for the Hypertext Access file, a distributed configuration file that controls access per-directory on an Apache-based web server. Here, the controlled access to current directory means one needs to verify its authority to access the content in that directory.
We are well aware about the Internet Application Protocol HTTP i.e. Hypertext Transfer Protocol. When the user visits any website, the site address (technically the URL) is identified by the HTTP daemon program. The HTTP daemon uses the .htaccess files at directory-level along with global access configuration files at root-directory-level. On receiving a web page request, it searches in the .htaccess file to verify whether the visitor has authority to access the content on that page. If yes, then he is asked to enter his username and password. Hence, in this way, the .htaccess plays its roles in the access control configuration of requests to the web server.
What is the need to edit .htaccess file?
Basically, as aforementioned, it specifies which users have authority to access the files in current directory. This file is usually not suggested to be enabled as it affects the performance of the web server in responding to the web pages’ requests. These days, it is able to override content type, character set and other such subsets of configuration settings. Yet all the web hosts permit editing of the .htaccess file thus, enhancing the flexibility of the administrator to facilitate the user access issue to its website. Apart from monitoring user access, the .htaccess file can also be used to disable directory indexes i.e. to turn off visibility of important directories, modify the default 404 page, attend the .html file as .php file, redirect users to another page, block/permit visitors using IP addresses, and to use a different file as the index file and so on. Do not worry if some web hosts do not permit editing of .htaccess files; you can still create your own one to control the configurations of those directories (and of course the sub-directories) under which you create and upload it.
Steps to edit .htaccess File on HostGator
1. Log in to your cPanel Administration of HostGator account and go to ‘File Manager’ under the ‘Files’ section. Check the ‘Show Hidden Files’ option so that you can view and access the .htaccess file.
2. The .htaccess file is located in the root directory of your website, which is, by default, public_html in the HostGator hosting account. If there exists no such file in public_html directory, then you need to create one under the same.
3. Creation of this file is very simple; just click on the ‘New File’ option provided above and proceed.
4. To edit the existing .htaccess file, click on the ‘Edit’ option above. A simple text file appears where you can make the required changes.
5. In case your edited file has any mistake, be it even a syntax error, your site won’t be accessible. Hence, ensure that you avoid such errors.
The .htaccess file allows configuration of the web server and access control files at directory-level. The editing of .htaccess file is very easy; it’s in the hands of website administrator how much flexibility he wants to provide to his site viewers and readers. However, enabling this reduces the site performance and affects its efficiency in a negative manner. Using .htaccess file slows down the Apache server and quality response to http. On the other side, users have mistaken that user authentication ought to be done in this files; whereas the fact is, .htaccess file should be brought in usage only when the main server configuration file is not accessible. Remember that, merging of .htaccess files with the main configuration file is possible. Hope that you have been acknowledged enough to access and edit the .htaccess files the way you want!