htaccess - uses advantages and disadvantages

What is .htaccess File? – Uses, Advantage, and Disadvantage

What is .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 with such as Drupal, WordPress, and Joomla you can easily encounter .htaccess file. These kind of files are able to make the edit within it to add rules, which is 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 type of restriction and to 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,

# BEGIN 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.

Advantages of using .htaccess file

  1. Mod_Rewrite
  2. Authentication
  3. Custom Error Pages
  4. Mime Types
  5. SSI (Server Side Includes)
  6. Redirects
  7. Restricting users based on IP
  8. Leveraging Browser Caching
  9. Enabling CORS
  10. 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.