Hosting Tutorial & Guide

What Is .htaccess File & How to Edit It?

updated on Jan 08, 2015
What Is .htaccess File & How to Edit It? .htaccess file is a familiar term for most webmasters but many beginners have no idea about this important feature offered by their web hosts. In this case, we work out this basic tutorial to present details about the definition and the main usage of a .htaccess file, and to offer a simple guide on how to access and edit the file. Just keep reading to get the information you need.

What Is .htaccess File?

A .htaccess file is a hidden text file working for configurations on Apache web servers. It contains many instructions which enable or disable additional functionality of the web server to adjust how the server takes actions to certain content, so it affects the way your website functions directly. The file controls how visitors and viewers can behave on your site, and it can block a certain part or the whole site to be inaccessible to particular traffic.

.htaccess is actually an extension to files on your server, while when you intend to find a .htaccess file, you will notice that there is no file name but only the extension instead. The extension tells the server what the file is. You can check whether you have a .htaccess file by using the file manager in your control panel to view the hidden files.

.htaccess files are widely used in the many aspects related to the control of website and file access. The most common usages are listed in below.
  • Password Protect Directories. A .htaccess file can be used to manage the authorization of directories, which adds security restrictions to website files.
  • Rewrite URLs. .htaccess is required to rewrite long and complex URLs to be memorable and understandable for readers and search engines.
  • Block Traffic. You can use the file to deny visits from specific IPs and domains.
  • Enable Cache. With .htaccess files, servers are able to control the caching for browsers and proxies to improve website performance.
  • Customize responses for server errors. You are able to set up custom 404, 403 or other error pages to better respond to server errors.

How to Edit .htaccess File?

How to Edit .htaccess File There are several ways to make changes to a .htaccess file. For example, you can edit the file on local computer and then use FTP to upload it to the server, take use of the Edit Mode of your FTP client, edit it with the File Manager in cPanel, and more. As editing through cPanel is the most convenient and quickest way, we mainly discuss this method here. Before following the steps below to access and adjust the file, remember to backup the file or the whole site first in case any error happens to your website.
  1. Log into cPanel control panel.
  2. Navigate to Files section and locate the icon that says File Manager.
  3. In the Directory Selection part, check Document Root for and then select the domain that you want to manage in the drop-down menu.
  4. Check the box next to Show Hidden Files. Then click to Go. Now the File Manager shows the files of the selected domain in a new tab.
  5. Scroll down to find .htaccess in the list, right click the file name and click on Edit.
  6. When the dialog box pops up to enquire about encoding, click on Edit.
  7. When the text editor opens in a new window, make changes as you need and click Save Changes when everything is done.

Now you have successfully edited your .htaccess file, and what you need to do is to test the website to make sure that things are right. If there is anything wrong, check the changes you have made or revert to the previous version if necessary.