What is .htaccess File?

The .htaccess file is a server configuration file. It allows you to define rules for your server to follow for your website. It’s able to override many server configuration settings and can be used for authorization, cache control, website optimization and URL rewriting.

In WordPress, the .htaccess file is used most commonly for rewritting URLs, making them cleaner, and more readable by humans and search engines. So, WordPress uses .htaccess file to generate SEO friendly.

In the Settings > Permalinks section of the WordPress Adminstration, you have the option to select your URL structure. WordPress will automatically rewrite your .htaccess file to handle the URL structure you select. If WordPress is unable to write to the file , it will ask you to do it manually.

How to edit .htaccess File?

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

There are Many Ways to Edit a .htaccess File

  • Edit the file on your computer and upload it to the server via FTP
  • Use an FTP program’s Edit Mode
  • Use the File Manager in Cpanel

Before editing your .htaccess file, it is important to download a copy of it to your computer as backup. You can use that file in case anything goes wrong.

The fastest and easiest way  to edit a .htaccess file for most people is to use the File Manager in cPanel.

First, open the File Manager :

  1. Login to cPanel.
  2. Click on “File Manager” in the “Files” section.
    .htaccess file
  3. Select “Document Root for:” and select the domain name you wish to access.
  4. Make sure “Show Hidden File (dotfiles)”  is checked.
  5. Click the “Go” button.
    The File Manager will open in a new tab or window.
  6. Look for the .htaccess file in the list of files. You may need to scroll to find this file

Next, Edit the .htaccess File

  1. Right click on the .htaccess file and click “Code Edit” from the menu. Alternatively, you can click on the icon for the .htaccess file and then click on the Code Editor icon at the top of the page.
  2. A dialogue box may appear asking you about encoding. Just click Edit to continue. The editor will open in a new window.
  3. Edit the file as needed.
  4. Click Save Changes in the upper right hand corner when done to save your changes.
  5. 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.
  6. Once complete, you can click Close to close the File Manager window.