Skip links

How to edit the htaccess file – WordPress

In this post we are going to show you how you can edit your htaccess file that exists on your WordPress website. If you missed our previous article about how you can keep your WordPress website safer please take a minute to read before you start editing the htaccess.

What is the htaccess?

Before we explain what is a htaccess file keep in mind that Apache recommends that we should avoid using the htaccess file because it can slow down the Apache http server. If you have access to the main http config server file then use it along with the <Directory> block and we are going to talk about the server configuration in one of the next posts so stay tuned.

Htaccess is a configuration file based on per-directory that provide ways to configure your instance instead of the main configuration file that Apache uses on your install. Once you apply the changes to your file Apache will read it and apply the instructions to your website only. It is important to know that when you change the main configuration file on your server you are going to apply those changes to all the websites that are running on your server which is what the previous paragraph talks about, so let’s say you are running multiple websites on your server and you don’t want to apply certain configurations to some instances them you should definitely use it in this case.

I can’t see my htaccess!

The htaccess is a hidden file and in most cases this file lives in your root directory on the same path as the wp-config.php. If you are using Cpanel make sure to enable the option to show hidden files. It is very simple! Open your Cpanel and go to file manager then on the new window find the option Settings which is located on the top right side of your window and tick the option show hidden files. After this change you will be able to see the file, if you don’t see a file after installing WordPress on your website then you should first go to the wp-admin area then hover over Settings and click in Permalinks. Choose the option that best fits your needs and click in save and then go back to the file manager and refresh the page.

If you do not use Cpanel no worries, just connect to your website using FTP or SFTP then go to the root directory and check if you can see the htaccess. In some FTP tools you have to enable the option just like the Cpanel file manager. I personally use FileZilla and to enable this option go to the menu bar at the top of the screen select Server and then choose showing hidden files.

What can I add to this file?

There are many configurations that you can add to your file for example the link structure that WordPress build on your website is based on the htaccess configuration, caching and compressing static files like CSS, JS and HTML are done on your htaccess file as well, PHP configurations and many other options. We are preparing an article that it is going to show you how you can speed up your website using the htaccess file only!

Default file permission

Always check the file permission and make sure you are using 644 or 664 for the htaccess. This file does not need any permission to be executed at all so make sure to take a look before start editing.

If you are facing any trouble on your website or having a hard time to maintain it please contact us today and ask about our custom hosting solution and management platform, also if you want to read more about the htaccess file please visit the Apache Software Foundation official website.

Leave a comment