In this guide, we’ll introduce you to the WordPress .htaccess file, explain how it works, its purpose, and discuss how to create and edit it. The htaccess (hypertext access) file is a configuration file for web servers running the Apache software. This file generally controls the directory it is placed and other directories inside the parent directory. There are lots of functionality you can add or control using the .htaccess file. Some basic features are:

Setup a 301 Redirect

Password Protect a Directory

Rewriting URLs

Cache-Control

WordPress htaccess File Creation Guide

Usage And Purpose

The purpose of this file is to reconfigure specific settings of the Apache Web Server. Thus, it can prove to be useful when toggling certain features of the server on or off. For instance, a typical use-case of the file is to create redirects from non-www to www URLs and vice versa.

Other uses include setting privileges for certain files, blocking bots or adding MIME types. It is particularly beneficial for taking care of the security settings of your WordPress. These features come in handy during WordPress development, as you will have to configure some of these settings best suited to your needs.

In most cases, the .htaccess file comes by default with every WordPress installation. But some times it stays hidden in the installation root folder. Here is the default code for the WordPress htaccess file:

# BEGIN WordPress
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Now if you want to add some codes in your WordPress .htaccess file or you want to create a new one but you have no idea how you can do that, then you are in the right place. First I will show you how to find WordPress .htaccess file in your cPanel.

Where Is The WordPress htaccess File in cPanel?

Generally, this file is already created when you install WordPress on your web host. But the period that starts the file name will keep the file hidden within the folder.

Login to your cPanel and Click on File Manager under File Management Section. When you click on File Manager, a little Window will pop up and you can find several options to choose while opening File Manager. WordPress Installation root directory is the Default WordPress .htaccess File Location. Make sure, you check the box which says “Show Hidden Files (dotfiles)”. Then Click on Go.

Now you can see .htaccess file in your file list. Right Click on the file and Click on Edit. A new window with a text editor will open up. You can edit your .htacces file and save the changes from the Editor. Access the file manager using an FTP server. You can access files using an FTP Client (FileZilla).

Creating WordPress htaccess File in cPanel

If there is no .htaccess file in your WordPress installation root directory, you can easily create one from your cPanel and you should. Here’s How to Create the file. Access your File Manager following the above steps. Now on the upper left of your Screen, you will see an Option – “New File”. When you click on ‘New File’, a little window will Pop up. You can set the file name and directory here. Follow the image below.

Now put .htaccess on New File Name field. Remember .htaccess is not an extension. It’s the file name. And there will be nothing before the period. It should not be something like text.htaccess. It’s only .htaccess. Now, click on “Create New File”. Reload your file manager. You’ll find the newly created .htaccess file on the list.

A Plugin to Edit htaccess File

If you don’t want to access your File Manager or FTP to Edit your .htaccess file, you can use plugins to edit it. For example, WordPress SEO by Yoast has a Feature to edit your Robots.txt and .htacces file from your dashboard.

Conclusion

The .htaccess file is mandatory for WordPress to work properly. It can provide a handle on additional features of the web server, especially as they pertain to security settings such as preventing spamming, blocking bad bots, etc. Now that you are somewhat familiar with the WordPress .htaccess file, you can move on to further explore what is possible with it, for the betterment of your WordPress project.



Share This Post