What is .htaccess File? – Uses, Advantage, and Disadvantage
By Surya
Table of Contents
What is a .htaccess File?
.htaccess file is a short name of Hypertext Access. It is a configuration file, used mostly by Apache web servers that control the directory. If you are using Content Management Systems such as Drupal, WordPress, and Joomla you can easily encounter a .htaccess file. These kinds of files can be edited within it to add rules, which are supported by several web servers. In this article, we are going to emphasize what is .htaccess file and how to use it.
In simple words, .htaccess is a file which is will be executed before every request on your domain/webserver.
Generally, these files are located at the root of your domain. We can use .htaccess files for various types of restrictions and use various Apache settings without changing the main php.ini.file
Creating a .htaccess file
You can create .htaccess file using any text editor such as TextPad, Ultra Edit, WordPad, etc.,
Example of default .htaccess file of WordPress,
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Uploading a .htaccess file
Once after creating it, you need to upload it, which can be done using FTP. When uploading, it is important you need to upload the file in ‘ASCII’ mode. These type of files are transferred using ‘BINARY’. It is likely your FTP software will default to “BINARY’. So look for a ‘Transfer Mode or Transfer Type’. In another way, you can upload .htaccess file through cPanel if you have access to it. In cPanel, you have to upload .htaccess file under “public_html” directory.
Why .htaccess file is hidden and how to find it?
Filenames that start with a dot ( . ) are hidden files, which directly means you cannot directly view this file in the default interface.
If you would like to access .htaccess file, Your FTP client or File Manager will have a setting like “show hidden files.” Name of the options might vary based on different platforms that you try to use, but is usually in “Preferences”, “Settings”, “Folder Options” or “View” menu.
How to Access .htaccess file in cPanel and Edit?
Step 1: Log in to cPanel and select “File Manager”
Step 2: Navigate to the “Public_html” folder. On the right top corner, you will see an option as “settings“. Click on that and enable “Show Hidden Files (dotfiles)” as shown in the below screenshot.
Step 3: Now, You will see the .htaccess file inside the Public_html folder. Right-click and edit to do any modifications.
Advantages of using .htaccess file
- Mod_Rewrite
- Authentication
- Custom Error Pages
- Mime Types
- SSI (Server Side Includes)
- Redirects
- Restricting users based on IP
- Leveraging Browser Caching
- Enabling CORS
- Hotlink Protection
Disadvantages of using .htaccess file
There are two major things which must be aware is the speed and security of the site.
1. Speed:
At sometimes, .htaccess page may slow down the website. This is because of the location of the portal of the page. It leads to affect on pages in its directory and all directories under it. If in case you have access to httpd.conf file, then it is recommended to do modification over httpd.conf server file.
2. Security:
.htaccess file allows the individual users to add/modify the configuration or rules of a server, which pulls out some of the security concerns through it, if in case it not properly handled.
More Resources for More Knowledge: