Articles on: WordPress

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:

Login to cPanel

Click File Manager

Navigate to the directory WordPress is installed

Click + File on the top navigation menu (below the cP logo)

Name the new file .htaccess

Click Create New File

Screenshot Of Step 5:



Once the file is created, 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)":



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

RewriteEngine On   
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]   
RewriteBase /   
RewriteRule ^index\.php$ - [L]   
RewriteCond %{REQUEST_FILENAME} !-f   
RewriteCond %{REQUEST_FILENAME} !-d   
RewriteRule . /index.php [L]

# END WordPress


The finished product should look something like this:



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 too 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.

Updated on: 10/10/2024

Was this article helpful?

Share your feedback

Cancel

Thank you!