Why WordPress htaccess Is Important And How To Create It

One of the most common problems we get in our support desk is with errors in the WordPress htaccess file.

If you're just installing WordPress for the first time, there isn't an .htaccess file.  It's not until you customize your permalinks and save that it automatically generates in the directory you have WordPress installed.

When WordPress cannot gain permissions to automatically generate the file (which can be for a number of reasons) you may find yourself needing to creating your own and uploading it manually.

Manually Create WordPress htaccess

You can easily do this by creating the file inside of cPanel's file manager:

  1. Login to cPanel
  2. Click File Manager
  3. Navigate to the directory WordPress is installed
  4. Click + File on the top navigation menu (below the cP logo)
  5. Name the new file .htaccess
  6. Click Create New File

Screenshot Of Step 5:

Create WordPress .htaccesd

Once the file is create, you need to add the content.

Enable Hidden Files In File Manager

By default, File Manager, nor most FTP programs show files that start with a period.  To enable this in File Manager, click the settings cog at the top and click the checkmark beside "Show Hidden Files (dotfiles)":

Show Hidden Files

Click save and you'll see the new file you created.

Default WordPress htaccess Content

Click on the .htaccess file, then click edit, and fill it with the following default WordPress .htaccess code:

# 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

The finished product should look something like this:

Save .htaccess

Click Save Changes and you will be all set!

Subfolder WordPress htaccess

If WordPress isn't installed in the root directory you'll want to use a slightly modified version of the .htaccess:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

SubDomain WordPress htaccess

The same goes for those that choose to install WordPress in a subdomain:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

If You Already Have An htaccess File

If you have other software on your website besides WordPress you may already have an .htaccess file.

If so, simply edit your existing file and copy and paste the above codes into it.

Important: It's always recommended to take a backup before modifying any existing files (trust me I've been there not doing it).

Why htaccess Is Important For WordPress

The .htaccess file helps route your URLs.  It's important to ensure your pages and posts generated by WordPress are named correctly and will be indexed properly by search engines.  Some WordPress plugins can alter this file and cause your entire site not to be viewable.

Making a new htaccess file for WordPress isn't to complicated but you ALWAYS want to make sure you have a backup if altering your old one.  A good way to do this is to download it to your computer or re-name the existing one .htaccess.bk.

Additional information on your WordPress htaccess file including how to customize it can be found in their support docs.

Feel free to ask any questions below!

  • 3 Users Found This Useful
Was this answer helpful?

Related Articles

 How To Reset Your WordPress Admin Password

Bookmark this page... You're going to eventually need it :) I don't know about you, but I run so...

 How To Set Your Homepage In WordPress

Today WordPress powers around 30% of all sites on the Internet. That's a staggering number. And...

 How To Clone Your WordPress Website Automatically

Step 1. Prepare Your Destination The first thing you need to do prior to cloning your website,...

 How To Remove Theme Footer Links

Most WordPress themes display their name with a link back to their site. Here's an example:...

 How To Backup Your WordPress Database Automatically

In a previous article, I'd shown you how to connect to your MySQL WordPress database remotely...