An Apache web server configuration file is an ordinary text file, held centrally on your webserver (assuming your webserver is running on Apache).
Many shared hosting companies use Apache including the shared host that we currently recommend.
These files go by different names depending on how high up the hierarchy they are on your server, but they are all configuration files.
The settings you type into a server configuration file control how your web server behaves.
Many of the settings within the configuration file will apply to all the websites on your server depending on which level of file we are talking about.
You can also create sections with the configuration file specifically targeted at individual websites on your server. Using this facility means you can tailor certain settings to each site when required.
Why An .htaccess File Is Needed
If you run your own VPS then you can (of course) do whatever you want as you are in are in charge.
But in a shared or managed hosting environment it would be tedious to have to contact your host every time you had to change the Apache server configuration file for one of your sites.
This is how the idea of the .htaccess file came about. It applies to a single website and sits in the same directory (folder) as the files for each website.
There can be multiple .htaccess files for each site, where for example you have different .htaccess files in different sub-folders of a single website.
However typically, we only need a single .htaccess file in the root directory where each individual WordPress site is installed.
The contents of a site’s .htaccess file, apply only to that one website and will override any conflicting settings in the central configuration files.
Ways To Access Your .htaccess File
There are 3 typical ways to edit your .htaccess file so that you can edit it :
- Use cPanel’s File Manager
- Use an FTP client such as Filezilla
- Use the Yoast SEO plugin (note! use only for small, safe edits)
One Mistake And Your Site Will Disappear
Any mistake in the .htaccess will result in the webserver returning a blank page to visitors.
So, here are a few precautions to limit the impact of errors:
- Take a backup copy of the .htaccess BEFORE you make any edits. Save the backup on your desktop or somewhere else that is handy in case you end up having to restore it
- Make your changes then double check, and triple check them
- Save your changes and then test the site immediately in a different browser – this reduces the risk of picking up a cached page
- Also check that the WordPress admin pages still function and are present.
- If the admin site or the main site shows a blank page your .htaccess file is broken so immediately restore it from the backup copy
Note that restoring the backup copy is only possible using cPanel or FTP, not when using the Yoast plugin as the plugin relies on the site being operational and it is not.
Updating the .htaccess File Using cPanel File Manager
This is the preferred method as it offers powerful direct editing of the .htaccess file, and is accessible whether the file contains an error or not.
- Find File Manager in cPanel
- Login in to your cPanel and scroll down and click the File Manager icon. Ensure you check the option to show hidden files when File Manager opens.
- Find Your Website
- Find public_html and navigate to the root folder of the website whose .htaccess file you want to edit. Select the .htaccess file and right click and choose Code/Edit
- Make Your .htaccess Edits
Make your changes carefully, save your changes then test the site to make sure it is still working okay.
Updating the .htaccess File Using FTP
With this method you can use an FTP client such as FileZilla to download the .htaccess file, save a backup copy to the desktop, then edit the file and upload it. This will work whether the file is valid or not.
- Connect To The Site
- Firstly connect to the site and navigate to the root folder
- Edit The .htaccess File
The file is opened in a popup window using your default local text editor (Notepad, TextEdit, etc).
Make your changes, save and close the window. FileZilla will then ask if you want to upload your changes to the website. Confirm the change then test your site to make sure everything is still working okay
Updating the .htaccess File Using The Yoast SEO Plugin
If you make a mistake the site will disappear and so will the admin site so you will NOT be able to use the plugin to fix the error. Instead you will need cPanel or FTP to get your site back again. Therefore you are advised to use this method only for the simplest changes, and where you have access to FTP or CPanel available should you need it.
- Find The Tools Option in Yoast SEO
- Go to the WordPress Admin Dashboard and click on SEO and then Tools.
- Edit The .htaccess File
- choose the File Editor and then edit the .htaccess file and having double and triple checked your changes click the Save changes to .htaccess button.