How to Create or Edit .Htaccess for WordPress?

WordPress is the world’s most popular website-building platform for a reason. It takes close-to-zero technical expertise to manage a website on WordPress. However, knowing about some of the important files and folders will make your life much easier. One such file is the .htaccess file. If you are running and managing websites on WordPress for a while, you must have stumbled across the need to access or edit the .htaccess file.

This article will show you two ways to access and edit .htaccess file. Before getting into it, let us dive a little into what the .htaccess file is and how to edit .htaccess file.

What is the .htaccess file?

The .htaccess file is one of those files that are created by default when you install WordPress. The .htaccess file is extremely important as it enables you to provide specific commands to the hosting server. The file is used to perform instructions such as redirects, changing website configuration, securing your website, and so on.

For example, if you want to restrict access to a particular page because you are making changes to it, the .htaccess file allows you to secure it with a password. In the next section, we talk about how you can find and edit .htaccess file.

 

Where is htaccess file located?

. htacess file is located in the root directory of the WordPress site installation folder. The root directory path name may differ depending on the hosting provider but in SeekaHost, you can find the WordPress files and WordPress .htaccess file under the “Public_html” folder.

 

How to Access the .htaccess for WordPress:

As mentioned above, the htaccess file is located in the root directory of your WordPress site. However, it is typically hidden. WordPress keeps the file hidden by default to protect it from any potential danger like getting accidentally deleted.

To access the .htaccess file, follow the steps mentioned below:

1. Log into your WordPress hosting account and navigate to cPanel.

2. In the Files section, go to the File Manager by clicking on it. You will see various website directories and website files.

3. For accessing the .htaccess file, navigate to Settings in the upper right-hand corner of the File Manager. You will see a Preferences window appear.

4. See if the Show Hidden Files (dotfiles) checkbox is selected. If not, check the option. You will see the page refreshing and all files starting with a . (dot) will now be displayed.

5. Save your changes by clicking on Save.

You will now be able to locate the .htaccess file in the list of files. Now let’s take a look at how you can edit .htaccess file.

Default .htaccess for WordPress:

A default .htaccess for WordPress website that will help to control how the server runs. Also, to access your website index file and modify rewrite rules.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

How to Edit .htaccess for WordPress:

Before we proceed to discuss the various ways in which you can edit .htaccess file, we advise you to take a complete website backup before editing your .htaccess file. The importance of a backup cannot be emphasized enough. To begin with, there is the risk of accidentally deleting the file or modifying it incorrectly. Furthermore, the modifications may not turn out as you want them to. Hence, taking a full website backup is strongly advisable.

We’ll take a look at two methods to edit .htaccess for WordPress.

  • Directly from cPanel
  • Using a Plugin

You can also use an FTP client to edit your .htaccess file. However, these two methods are the simplest. Let’s dive into these methods to edit .htaccess file.

ALSO READ: How to setup 301 Redirect in .htaccess file? 

Method #1: Edit .htaccess file in cPanel

1. Log into your hosting account and go to cPanel. Then, navigate to the file manager.

2. You will see various files and folders. Navigate to the public_html folder to find the htaccess file in cPanel.

3. Right-click on the .htaccess file and hit Edit. You will see the .htaccess file opening in another window where you can make changes to it as per your requirements.

 

Method #2: Edit .htaccess file using the Htaccess Editor plugin

The method mentioned above has a little element of risk involved. It includes accessing and editing WordPress files manually which can go drastically wrong. Using the Htaccess Editor plugin is a safer method. You’ll find various plugins for the function of editing the .htaccess for WordPress. However, the Htaccess Editor plugin offers a simple process to edit the .htaccess file.

It is always advisable to stage your WordPress website and test the plugin to check for compatibility issues. However, the plugin is highly unlikely to cause any of those. So, let’s move right into the process of installing and setting up the plugin.

1. Click on Plugins in the left sidebar of the admin dashboard and then hit Add New.

2. Search for “Htaccess Editor” and find the plugin by Web Factory Ltd. Install the Htaccess Editor plugin and activate it for your WordPress site.

3. Once activated, you can use the plugin by navigating to Settings in the admin dashboard and clicking on WT Htaccess Editor. It will take you straight to the .htaccess file without even leaving the dashboard. You can now see the default .htaccess WordPress code and can edit .htaccess file as per your requirements and save the changes.

ALSO READ: Disadvantages of using WordPress Plugins in Your Website

Wordpress .htaccess editor

Conclusion

And there you go! You now have half the knowledge it takes to be a WordPress expert. Jokes aside, knowing how to edit .htaccess file allows you to do a wide variety of things with your website. One thing to keep in mind is that you should always make backups before making edits to it.