How to Create Default WordPress .htaccess File?

May 21, 2019

How to Create Default WordPress .htaccess File?

May 21, 2019

Anyone can build and run a WordPress website without any knowledge of the underlying files and folders.

But someday, it is possible to find yourself in a situation where knowledge about WordPress files and folders are required. There are times where you will need to troubleshoot problems or make modifications. That will require you to go behind the scenes and access your WordPress files.

Take the .htaccess file for instance. It’s one of the most important WordPress files and users can execute a lot of functions by modifying it. They could fix common WordPress errors, password protect certain pages on your website, restrict access to WordPress files, block IP addresses among a whole lot of other things. But sometimes it’s hard to locate the file.


Well, when you install WordPress, the .htaccess file is generated automatically. When WordPress cannot gain permissions to automatically generate the file (which can be for a number of reasons like the server is causing obstructions) you will need to create it on your own and upload it manually. This is not hard but the process is fraught with risks.

As we already mentioned, the .htaccess file is an extremely important file and a single mistake while handling the file could break your website. But don’t worry, we have a tried and tested process that will help to create a .htaccess file and upload it with great precaution, without breaking your site.

Before we dive into the process of creating and uploading the file, it makes sense to learn about what the file does and why it’s considered so important!

What is the .htaccess File in WordPress?

We mentioned earlier that the .htaccess file is generated automatically when you first install WordPress. The file enables you to give instructions to your web server. You may want to modify your site settings, redirect pages, or apply security measures. To make these modifications, all you need to do is edit the .htaccess file and add snippets of code.

If you are planning to work with WordPress sites, then learning about the .htaccess is a step in the right direction. Click To Tweet


Where is the .htaccess File Located in WordPress?

The .htaccess file is found at the root of your WordPress install. What does that mean? Let’s take a step back.

WordPress websites are made up of many files and folders. If you could go behind the scene access your files through the File Manager, you’ll see that there are many WordPress folders and sub-folders. The biggest WordPress folder in any WordPress install is the public_html folder. It is sometimes also known as the root directory or root folder.

You’ll find your .htacesss file inside this root folder. We’ll show you the exact steps that you can take to locate the .htaccess file in the next section.

How to Find the WordPress .htaccess File?

But hold on… To find the .htaccess file, you’ll need to access the backend of your site which makes the process risky. One mistake can cause your website to break. So make sure you are taking a complete website backup. If something does go wrong, you can restore your website back to normal.

Step 1: Log into your hosting provider’s account and go to your cPanel and select File Manager. You also can use any of other ftp client such as Filezilla.


file manager in cpanel

cPanel > File Manager


Step 2: Once you are the File Manager, click on the public_html folder and look for the .htaccess file within that folder (see the picture below).


htaccess file in public_html folder

Inside the public_html folder is the .htaccess file


IMPORTANT: Quite often WordPress hides the .htaccess file to deter people from fiddling with the important WordPress file. If you can’t find your .htaccess file, then it’s very likely hidden. Don’t worry, we’ll tell you exactly how you find it.

Step 3: From the File Manager, select Settings which is generally located up in the right-hand corner of the page. A pop-up will appear where you’ll need to choose the option Show Hidden Files. Save the changes and go back to the File Manager. Inside the public_html folder, you’ll find the .htaccess file.


Select Show Hidden Files

Select Show Hidden Files


If you still can’t see the .htaccess file, it’s possible that your website has no .htaccess file.

We mentioned earlier that in certain circumstances, the .htaccess file could be missing from your website. For instance, your web server prevented WordPress from generating the file or one of your users could have deleted it. In such cases, you need to create a new .htaccess file and well show you how exactly you can do that.

How to Create a WordPress .htaccess File?

There are 2 ways to create a .htaccess file –

  1. By Setting Permalinks
  2. Generating .htaccess Manually

1. By Setting Permalinks

Earlier in the article, we spoke of how you can perform many functions like redirecting and keeping your pages password protected with the help of your .htaccess file. But on its own (i.e. without anyone making any modifications on the file), the default WordPress .htaccess file has a few tasks to perform. These tasks are related to your site’s permalinks. You’ll need the .htaccess file to ensure that your website URLs are working properly. Since permalinks are so closely associated with the file, they’ll enable you to generate one. Here’s how –

Log into your WordPress website and navigate to Settings > Permalinks. Scroll down the page and click on Save Changes.


Go to Settings and Permalinks

Go to Settings > Permalinks


This will generate the .htaccess file but to be completely sure, log into your WordPress hosting account and go to the File Manager. From the File Manager, select public_html and inside this folder, you’ll find the .htaccess file.

2. Generating .htaccess Manually

On rare occasions, WordPress may not be able to generate the file because your web server is denying permission to create a file. In that case, you will need to create the file manually and upload it to your website.

a. Open a text editor like the Notepad on your computer
b. Now copy and paste the following code into the editor –

# BEGIN WordPress

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteRule ^index.php$ – [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]


# END WordPress

c. Save the text file as “.htaccess” file.

IMPORTANT: Make sure that the file name is not simply “htaccess” – it has a full stop (.) at the start. Make sure there are no extensions like “.txt”

d. Now it’s time to upload the file. But before you do that, make sure you manually backup your site. If things go wrong, you can restore your site back to normal.

Log into your hosting account and go to the File Manager. From the File Manager, choose the public_html folder (the htaccess file will be saved inside this folder). Then select Upload and upload the .htaccess file from your computer.


htaccess file in file manager

File Manager > public_html > Upload


And that’s it. You’ve successfully created a .htaccess file for WordPress website.

Final Thoughts

If you are planning to work with WordPress sites, then learning about the .htaccess is a step in the right direction. There are a wide variety of functions that you can execute on your website with the help of the .htaccess file. Once you get the hang of it, all you’ll need to do is open the .htaccess file, add a code snippet and a new functionality will be at your fingertips.

But working with the .htaccess is like treading on eggshells. One slip and you can end up causing your site to break. Hence, you need a safety net. Take a complete backup of your website so that if you make a mistake, you needn’t worry. Simply restore your backup and get your site up and running immediately.

Take a Complete Backup of Your Site With BlogVault

Would love your thoughts, please comment.x