.htaccess is short for Hypertext Access, and is a configuration file used by Apache-based web servers that controls the directory that it “lives” in–as well as all the subdirectories underneath that directory. Also helps to create Custom Error Pages for Better SEO.
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 to enable/disable additional functionality and features that the Apache Web Server software has to offer.
You can create the .htaccess file in a text editor (make sure to name it only .htaccess without any other extension or name) and then upload it to your site through an ftp client. You can also create .html file in your File manager and create an file, and then name that file as .htaccess
Additionally the placement of the .htaccess file is important. The configurations in that file will affect everything in its directory and the directories under it.
What is the basic usages of htaccess file ?
The Disadvantages of .htaccess file
1. The slower speed and permision loss: The .htaccess file may slow down your server speed. If .htaccess files are allowed (via the AllowOverride directive) then apache will look for .htaccess files on every request. In addition, Apache has to look up the directory tree to see if there are further .htaccess files in locations above the location the file is requested from so that it can tell which directives have precedence. Each time a page loads, the server scans its directory, and any above it until it reaches the highest directory or an .htaccess file. A lot of wordpress cache plugins avoid using .htaccess files because of its httpd slower disadvantage.
2. The high risk Security: Not the administrator but all users can modify their own apache configuration files. Allowing individual users to modify the configuration of a server using .htaccess can cause security concerns if not taken care properly. The .htaccess file is much more accessible than standard apache configuration and the changes are made live instantly (without the need to restart the server). Granting users permission to make alterations in the .htaccess file gives them a lot of control over the server itself. Any directive placed in the .htaccess file, has the same effect as it would in the apache configuration itself.
The Advantage of .htaccess file
1. Immediate changes without restarting httpd server: any change in Apache configuration(httpd.conf) file need to restart the httpd apache server to take effect. By using .htaccess file, we can configure features of Apache and these changes will get reflect immediately because .htaccess files are read on every request by Apache Web Server software.
2. Not just administrator but all Non-privileged users can configure their own applications : As we know that Apache configuration file httpd.conf is only accessible and managed by administrator. It is not accessible or manageable by normal users. Now, a normal user can use .htaccess file to configure Apache configurations for their own application as per their need. Hence, main Apache configurations are still same for other application running on the web server.