WordPress htaccess File Creation Guide

In this creation tutorial guide, we will introduce you to the WordPress .htaccess file, explain how it works, how to create and edit it

By Claudio Pires
Updated on June 7, 2023
WordPress htaccess File Creation Guide

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. Therefore you can add or control many functionality using the .htaccess file. In this guide with a tutorial de creation, we’ll introduce you to the WordPress .htaccess file, explain how it works and its purpose, and discuss how to create and edit it. Some basic features are:

  • Setup a 301 Redirect
  • Password Protect a Directory
  • Rewriting URLs
  • Cache-Control

Usage And Purpose

The purpose of this file is to reconfigure specific settings of the Apache Web Server. Thus, it can prove to be helpful 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 specific 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 must configure some settings best suited to your needs.

In most cases, the .htaccess file comes by default with every WordPress installation. But sometimes, 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 to your WordPress .htaccess file or create a new one but you have no idea how to do that, then you are in the right place. First, I will show you how to find the 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 from while opening File Manager. The 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 the .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 ‘New File,’ a window will Pop up. You can set the file name and directory here. Follow the image below.

Now put .htaccess on the 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 files from your dashboard.

Final Words

The .htaccess file is mandatory for WordPress to work correctly. 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.

We hope this guide with a creation tutorial, introducing the WordPress .htaccess file, explaining how it works, and how to create and edit it, has helped you. Leave us a comment!

Claudio Pires

Claudio Pires is the co-founder of Visualmodo, a renowned company in web development and design. With over 15 years of experience, Claudio has honed his skills in content creation, web development support, and senior web designer. A trilingual expert fluent in English, Portuguese, and Spanish, he brings a global perspective to his work. Beyond his professional endeavors, Claudio is an active YouTuber, sharing his insights and expertise with a broader audience. Based in Brazil, Claudio continues to push the boundaries of web design and digital content, making him a pivotal figure in the industry.