Hello, In my recent tutorials, you have learned to tighten blog security and enable gzip compression using a .htaccess file on your server. Today, in this tutorial, I am sharing ways to access and edit the .htaccess file on your server.
First, let me tell you why we use the .htaccess file on the server. We use the .htaccess file to configure the server. Most bloggers use shared or managed hosting, where you have to contact the hosting provider whenever you need any modification on the server. So, this is a bit of a time-consuming process.
To overcome this, there is a file named .htaccess. You have to put this file in the WordPress directory to make changes for the particular website. You are allowed to use multiple .htaccess files to manage your websites. For example, you can use different .htaccess files for your subdirectories.
Ways to access .htaccess file
Following are the three typical ways to access your .htaccess file so that you can edit it.
- cPanel’s File Manager
- An FTP client such as Filezilla
- Yoast SEO plugin (note! Use only for minor, safe edits)
One mistake and your site will disappear
Any single mistake in the .htaccess file will result in the web server returning a blank page or error 500. So, some precautions should be taken while updating the .htaccess file.
Always make a backup copy of the current .htaccess file.
You can save the backup on your desktop so that if anything goes wrong, you can easily restore the backup file.
After a successful edit, check your website in different browsers. Clear browser cookies and cache;Â this reduces the risk of picking up a cached page.
Don’t use Yoast SEO for significant changes in .htaccess because if you break up with your site, you can’t restore the backup using the Yoast SEO plugin.
Edit .htaccess File Using cPanel File Manager
Editing a .htaccess file using the cPanel file manager is the recommended method as it offers powerful direct editing and is accessible whether the file contains an error or not.
To edit .htaccess file using the cPanel file manager, follow the steps:
- Log into the cPanel
- Scroll down and click File Manager
- Check the option to show the hidden files in File Manager
- In File Manager find public_html
- Navigate to the website’s root folder, the .htaccess file you want to edit.
- Select the .htaccess file, right-click, and choose Code Edit. Then, select the Download option to make a backup file on your desktop.
- Make your edits and save changes from the top right corner.
- Don’t forget to check your site after edits.
Edit .htaccess File Using FTP Client
To use this method, you can use FileZilla as FTP Client. By using FTP Client, you can make a backup file of your current .htaccess file on your desktop. It is also a safe way to edit .htaccess file.
To edit .htaccess file using FTP, all you have to follow steps:
- Connect your website using FTP Client (FileZilla).
- Navigate to the root directory of your site.
- Drag and drop .htaccess file from FileZilla to the desktop.
- Edit .htaccess file using an editor like, Notepad or Notepad ++.
- After editing, upload it to the directory.
Remember to check that your website is working after updating the .htaccess file. If it shows a blank page, you can upload the backup file to fix it.
Edit .htaccess file using Yoast SEO Plugin
Don’t use this method to make major modifications to the .htaccess file. If anything goes wrong, the site will disappear, and you will not be able to fix it using the plugin. Instead, you can use cPanel or FTP to fix it.
To edit .htaccess file, follow the steps bellow:
- Log in to the WordPress dashboard
- Navigate to the Yoast SEO option on the left navigation
-  Choose File editor
- Edit .htaccess and Save changes
Conclusion
These are the best three ways to edit the .htaccess file on your web server. Remember to make a backup of the current .htaccess file before you make any changes to it.