Web Design Blog

Backing up the .htaccess file in cpanel

The .htaccess file of WordPress website

What is the .htaccess file?

The .htaccess file is a configuration file for the  Apache Web Server Software that is installed on your hosting server. This file is located in the same directory as where your WordPress website is installed, and you may find a few other .htaccess files inside some subdirectories as well, where it controls that particular subdirectory and its sub subdirectories only.
If WordPress is installed in your root directory (http://www.yourwebsite.com/ ), you will find this file in the /public_html directory.
The .htaccess file can be used to alter the configurations of the Apache Web Server software to enable/disable additional functionalities and features that the Apache Web Server software has to offer.
You can create the .htaccess file in any text editor (feel free to name it htaccess.txt temporarily so you can see it and open it in a text editor, or this file will be visible on the Mac if it starts with a dot. Upload this file to your site to the same directory the website is installed in, using the File Manager. Then rename it .htaccess (exactly like this!).

Examples of what can be done with this .htaccess file (by using a plugin or doing it manually):

  • Firewalls
  • Security
  • Redirections: local(within the current domain’s directories/pages) or distant (to other domain name)
  • Access to subdirectories
  • Mime Types: Add the ability to server to execute of PHP on pages not ending in .php
  • Mod_Rewrite: how your URL will read in the browser address bar
  • Authentication: for example if a password is required to access certain sections of the website
  • SSI: “Server Side Includes” are a great time-saver for updating a large number of pages with some specific data, without having to update each page individually
  • Custom Error Pages: the .htaccess file additionally allows you to create custom error pages for your site. To make a page look friendlier and to provide more information to the site visitor than the default server error page offers, you can use the .htaccess file to create your own custom error pages, for these types of errors:
    • 400 Bad Request
    • 401 Authorization Required
    • 403 Forbidden Page
    • 404 File not Found
    • 500 Internal Error

Important .htaccess facts to know!

There are 2 types of website conditions that the .htaccess file can have an effect on.

One: Speed—the .htaccess page may slow down your server somewhat; for most servers this will probably be an imperceptible change. This is because of the location of the page: the .htaccess file affects the pages in its directory and all of the directories under it. Each time a page loads, the server scans its directory, and any above it until it reaches the highest directory containing an .htaccess file.

Two: Security—the .htaccess file is much more accessible than standard apache configuration on the server level, which may pose a security issue for your Website, and any changes made to the .htaccess file are made live instantly (without the need to restart the server). Granting users permission to make alterations in the .htaccess file gives them a lot of control over the server itself, so be very careful who to allow access to it. Any code placed, and any edits made in the .htaccess file, have the same effect as if they had been done in the apache configuration itself.

To View the .htaccess File

The content below assumes Wordpress is installed in the root directory of your domain but if yours is installed in a subdirectory, for example in a subdirectory named blog , then this content applies to blog instead: you will find blog located at public_html/blog .

You can view your .htaccess file when you log into your cpanel (yourwebsite.com/cpanel) and then click on File Manager and then on /public_html . This is the root directory of all websites using the Apache Server.

How to find the invisible .htaccess file

If you don’t see the .htaccess file in the proper directory, do the following: open File Manager and make sure to navigate to public_html or your subdirectory first. Then click on the button Settings at the very top right and put a checkmark in front of “Show Hidden Files (dotfiles)” and while at it, why not choose Web Root as your default directory for when you open File Manager in the future.
File Manager Settings
File Manager Preferences

How to Download .htaccess and Save As…

Then, when you find and see the file, click just once on its name in order to select it. Then in the toolbar above, click on: Download and make sure you remember where you save it on your computer. I recommend when using a iMac or Macbook, to save the .htaccess file as htaccess.txt (without a dot in front of htaccess to save it as a .txt file) because on a Mac the hidden files don’t show and I forgot how to make them visible.

How to Make a Backup of .htaccess

If you ever needed a backup of .htaccess, you could do one of two things.
  1. You copy the text on .htaccess by highlighting it first. Then click Edit, Code Editor or View. Highlight all the text and with right mouse button or Mac’s control + click choose copy. Then on your computer create a text file, call it htaccess.txt and paste it in there.
  2. You highlight the file and click Download. To use your backup file and remove the one that is up there now, first rename or delete that .htaccess file in File Manager. Click Upload (make sure to be in the proper directory first so it uploads in there). Click on Reload in second menu above. Highlight your uploaded htaccess.txt file and choose Rename from the top menu above and name it .htaccess Make sure it is exactly that name. If a popup comes up with a warning about file extension) do it anyway. Put nothing in front of the dot. This file has to start with a dot/period

Why back up .htaccess?

The reason you may be asked by a WordPress plugin to have a backup of the original .htaccess file is because the plugin in question is going to write to the .htaccess file. That is quite alright.
But in the unlikely event that the plugin’s modification to the .htaccess file contained just one small error, it would bring your entire website down. So never mess with that file yourself either, unless you know exactly what you are doing.
Leontine Vandermeer
Lionsites Web Design
941-445-5919

Leave a Reply

Name (Required)

Email (Required - will not be published)

Website

Message (Required)

Captcha * Time limit is exhausted. Please reload the CAPTCHA.