Most of the hosting providers (We recommend Hostinger, SiteGround, A2 Hosting, GreenGeeks, and Kinsta among others for audiences in Australia, Malaysia, UK, Singapore, Canada) that host the majority of commercial websites on the internet use a version of the popular Apache webserver software to configure how the hosting server will respond to specific requests. Most of these commands and rules are a part of a configuration file located on servers called the .htaccess file.

The way you configure a .htaccess file will directly connect the behavior of the webserver in certain situations or requests. It is also a perfect way to add functionality and security to certain parts of your website.

In this short guide, we will try to explain what .htaccess is, its purpose, applications, and how to edit it.

The Origin of the Name .htaccess

“Hypertext access” or .htaccess comes from the Apache webserver tool used for configuring file access in each directory. The tool’s main application was to restrict or allow secure access using a username or password to specific individuals. While the original role of the .htaccess was user control, the configuration file has a much broader application on today’s web servers.

What is the Use of .htaccess?

.htaccess is a configuration file placed in a specific directory on an Apache webserver. The file contains a bunch of lines that determine the behavior of the Apache Webserver in certain situations or during queries. .htaccess file takes control of the configuration of all the data located in that directory and all the accompanying subdirectories.

So, what are the most common uses for the .htaccess file? The possibilities are endless, but the configurations which appear the most are:

  • Error pages – Whenever an Apache Webserver needs to display an error page (404 Page, 401 Page, etc.)
  • Password protection – If individual pages of the website require secure password-protected access.
  • Redirecting traffic – If a page is no longer inactive, or traffic needs to go to a specific landing page.
  • SEO purposes – Creating a trailing slash policy, designed to boost the SEO of the website or specific pages.
  • Blacklisting and whitelisting IPs – if you want more control over who can have access to your website.

The applications for .htaccess files are growing every day, making it one of the easiest and most efficient ways to manage Apache Webserver behavior.

The Location of .htaccess File

Theoretically, every folder on the server could have its .htaccess file. Still, the essential .htacess file should always be in the webroot folder, which contains all of the subfolders and files of your website. If your site is inside a single directory, most likely, the subfolders will be within the webroot folder.  

Finding a .htaccess file might be tricky for those who are novice users. All files that have a name beginning in a dot instead of a letter, Apache Webserver, treats those files as hidden. If you are using an FTP client or file manager to access the files on your server, make sure to enable the Settings to display the hidden files. That is it!

How to Edit a .htaccess File?

To edit a .htaccess file or write a new one, all you need is a text editor. In most cases, .htaccess files will already be present in the folder, as it generates automatically. If the file is missing from the directory, creating a new one is a breeze. The key is to save the file in ASCII format to ensure compatibility with the Apache Webserver and upload them there.

The edits could be something minor like redirecting to a new error page, or something major. In any case, editing of .htaccess requires a bit of skill, but most novices and beginners should be able to pick it up without a glitch.