WordPress .htaccess File – Location, Create & Example

There is one file that controls several aspects of how your WordPress installation handles requests made to it, this is the .htaccess file. In this article, we will provide more information about it.

What is the .htaccess file to WordPress

The .htaccess file is a configuration file which is used by the Apache HTTP server to manipulate how your site handles requests made to it. For example, let’s say that your browser is a client which asks questions and the server is the person that will answer those questions. The client gives the server a note full of questions and the server needs to return another note containing answers to the questions asked. Depending on the .htaccess file and other configurations the server will return a different answer. The other configuration files are set by the server administrators and are not available for editing by the clients. The .htaccess file is the way that clients can manipulate how their sites behave as they have direct access to it and its content.

 Where is the .htaccess file located in WordPress

The main .htaccess file is located in the Document Root for your domain. For cPanel primary domains the Document Root is the public_html directory. You can take a look at our article on how to find your Document Root from here.

Notice how the .htaccess file has a .dot in front of it. This .dot makes the file part of the dot files in a Linux system, those files are usually hidden from the normal users as they are configuration files. In a cPanel environment, you can see the .dot files which are hidden by default from your File Manager by checking the Settings ->Show Hidden Files (dotfiles) setting

A screenshot of turning the cPanel Hidden Files display on

How to show hidden files in cPanel’s File Manager

Then you should be able to view the .htaccess file in the Document Root for the domain.

The main .htaccess file location for WordPress installations

WordPress .htaccess File Default Content

The default WordPress’ .htaccess file contains the following instructions in it:

# 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

Notice how there are comments that indicate where the default WordPress code starts and ends ( # BEGIN , # END ). Those are commonly used by plugins to add extra configuration options to your WordPress installation to instruct how the server should handle requests made to it.

The BEGIN and END are used to indicate where a plugin’s .htaccess code starts and ends. Some plugins might add their own rule for caching or security purposes and they usually are marked in the following format:

# BEGIN Plugin Name Rules
// rules which are added by the plugin
# END Plugin Name Rules

Create a WordPress .htaccess file

If you find that your .htaccess file is not created you can easily re-create it from your WordPress’ dashboard by navigating to:

BLACK FRIDAY 2022

WordPress Dashboard -> Settings -> Permalinks -> Click Save without making any changes

The .htaccess file should be generated with the correct default WordPress rules in it.

If you wish to re-create the .htaccess file through cPanel you’re also able to do that as well:

cPanel -> File Manager -> Navigate to the Root Directory of your domain -> +File (on the top left) ->New File Name: .htaccess

Create a file in cPanel

Create an .htaccess file

Once the file is created you can Edit it and enter the default .htaccess rules listed above in the file.

Editing an .htaccess file in cPanel

Saving the changes made to an .htaccess file in cPanel

Start your project with WordPress in a matter of minutes. Rely on our professional help and friendly staff – now all our shared hosting packages come with 40% OFF the regular price! Check our WordPress shared hosting packages!