WordPress htaccess file: What is it for?

wordpress htaccess file

Are you trying to understand what wordpress htaccess file is? If you came to our website looking for the keyword “wordpress htaccess file” on Google, probably it is because you don’t know what this file is and would like to know better what it is for.

No problem! We are here to help you. We will explain you exactly what this file is and, after a “theoretical” part, we will give you some useful tips to go and edit your .htaccess file in order to add additional features to your website.

Before doing this, however, you have to understand what the htaccess file is in WordPress.

What is the wordpress htaccess file?

First of all, let us tell you that this file is not strictly related to the WordPress platform. In fact, even if you go to use other platforms like Joomla or drupal for example, you will still find the .htaccess file inside the main folder where you installed your CMS.

This file is used to communicate with the hosting server you use so that it knows how to manage some features on your website.

Through the .htaccess file, you can do some very interesting things like:

  • Protect the administration area with a password
  • Protect important folders
  • Disable PHP language execution only on certain folders
  • Protect the wp-config.php file from any computer attacks
  • Make your website inaccessible to certain IP addresses
  • Much more…

If you are interested in some of these features, I have written below the code that you must go to insert in your .htaccess file in order to add special features on your website.

Where is the .htaccess file in WordPress

This file can only be found in the main folder where you have installed WordPress. To be clear, where you also find folders “wp-content”, “wp-admin” and “wp-includes”.

If the .htaccess file was created previously and you are going to delete or edit it incorrectly, it is highly possible that your website will stop working.

That said, if you usually manage the files of your website via FTP with an external program like Filezilla¬†or Transmit, it can happen that the software does not let you see this file as it is a hidden file. In this case, you have to understand how to “force showing hidden files” on your FTP software (you can try to search on Google).

Default .htaccess file by default

As I told you before, if you go to delete the .htaccess file your website would stop functioning properly. If, by mistake, you deleted this file and you are looking for a solution, here is the original default code that is automatically generated by WordPress:

# BEGIN WordPress
RewriteRule ^ index \ .php $ – [L]
RewriteRule. /index.php [L]
# END WordPress

You have only to create a normal text file on your computer using the “notepad” application that is installed by default on Windows (or a software like Atom, very useful to write clean code) and to follow these simple steps:

  1. Create a text file on your PC and name it htaccess
  2. Copy the text that you find above and save the file
  3. Upload the file in the main folder where you installed WordPress
  4. Rename the file to “.htaccess”

Once this is done, your website should return to work perfectly as before. If you have any problems, leave your comment below the article, I will try to help you as much as I can.

How to generate the .htaccess file with WordPress

It may be that if you have your own website that has just been created, you can not find the “.htaccess” file anywhere. Well this is completely normal, do not worry.

In fact, this basic file does not need to make your website work, but if you want to add some of the features that we’re going to see soon, you have to be in possession of this file.

How can you go to create it? Very simple, just go to the “Settings> Permalink” section on your WordPress admin panel and go to change the permalink structure. I strongly advise you to choose the “Article Name” structure as it can also be useful for SEO.

Once you’ve done this, you should find the .htaccess file on the main WordPress folder. Alternatively you can always create the file manually as we saw in the section above.


Please enter your comment!
Please enter your name here