Edit .htaccess File Print

  • 0

What is .htaccess?

The .htaccess is a configuration file that modifies how a website works in an Apache server.

How to Locate Your .htaccess File

Here is a video tutorial on how to locate the .htaccess file in your cPanel

How to Edit Your .htaccess File

The .htaccess file contains directives (instructions) that tell the server how to behave in certain scenarios and directly affect how your website functions.

Redirects and rewriting URLs are two very common directives found in a .htaccess file, and many scripts such as WordPress, Drupal, Joomla, and Magento add directives to the .htaccess so those scripts can function.

You may need to edit the .htaccess file at some point, for various reasons. This article covers how to edit the file, but not what to change. (You may need to consult other articles and resources for that information.)

Methods to Edit a .htaccess File

The fastest and easiest way to edit a .htaccess file for most people is to use the File Manager in cPanel; this article covers how to edit using this method and applies to Linux web hosting, such as HostGator Shared, Reseller, VPS, and Linux Dedicated Servers.  

How to Edit .htaccess in cPanel's File Manager

Before we do anything, it is suggested that you backup your website so that you can revert back to a previous version if something goes wrong.

To access the .htaccess file:

  1. Log into cPanel.
  2. In the Files section, click on the File Manager to open.

3. The File Manager displays different folders or website directories and website files - some of which are hidden. Select the directory you wish to access.

4. To see the .htaccess file, click Settings in the upper right-hand corner.

5. Make sure the Show Hidden Files (dotfiles) is checked. This will refresh the page and all files starting with a "." (dot) will be displayed.

6. Click Save.

7. Locate the .htaccess file in the list of files. You may need to scroll your cursor a little bit to find it.

 

To edit the .htaccess File:

  1. Go to your cPanel's File Manager.
  2. If you have a single domain, go to public_html to find the .htaccess file. (If you have other domains, access that domain's document root to edit the .htaccess.).

3. Right-click on the .htaccess file and click Edit from the menu. Alternatively, you can click on the icon for the .htaccess file and then click on the Edit icon at the top of the page.

4. A dialogue box may appear asking you about encoding. Just click Edit to continue. The editor will open in a new window.

5. When entering the codes needed, for example, for Redirects and Rewrites, you can paste the whole code from the second line in .htaccess.

When you need to add more codes, make sure to have an extra line before entering the new codes.

Click Save Changes in the upper right-hand corner when done.

Test your website to make sure your changes were successfully saved. If not, correct the error or revert back to the previous version until your site works again.

Once complete, you can click Close to exit out the File Manager window.


Was this answer helpful?

« Back

Powered by WHMCompleteSolution