Learn About The Web

Digital Marketing Tips – How to Create and Edit your WordPress .htaccess File

How to Create and Edit your WordPress htaccess File

Throughout many of these posts, you’ve been asked to access and edit the .htaccess file so now we’re going to look at what it is and how to create and edit it.

It is a very important system file that is in the root directory of your website and is one of the most useful tools you have for improving the speed and performance of your website.

What is .htaccess File?

The .htaccess file is a system file that belongs to Apache server. It is a configuration file which talks to the server and acts as per the instructions in the file.

Basically, it is the way in which the Apache server handles per-directory configuration changes. WordPress uses the .htaccess file to manipulate the way in which Apache serves the files from root and subdirectories.

The (.) at the start of the name signifies that it is a hidden file so, when you need to access it, you need to ensure that your system has ‘Show Hidden Files’ enabled.

How to Create an htaccess File

Most of the time, WordPress will automatically create the file the very first time you decide on your permalink structure.

However, sometimes you may need to do it yourself because WordPress can’t, usually because of read/write issues or create permissions issues with the server. So, here’s how to create it manually:

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

How to Edit the htaccess File

There are a few ways to access and edit the .htaccess file:

Through cPanel

Through Yoast Plugin

Yoast is one of the most popular plugins in WordPress and it allows you to access the .htaccess file and edit it. You could also use WP Htaccess Editor but, before you use any plugin to edit the file, do back up your website first.

Why Use .htaccess to Improve Website Performance?

It is one of the most important files for your website, offering options to enable and/or disable many safety features and change the way the search engine bots are handled.

You can also use it to add URL write/rewrite rules for redirections and it can be used to help safeguard against spammers on your website.

One of the most common uses is to enable GZip compression, or to add Expires Headers, change eTag to leverage browser caching and more. In short it is, as I said, one of the best ways to manage performance and speed.