WordPress Tutorial

How to Create Default WordPress .htaccess File

How to Create Default WordPress .htaccess File

WordPress is the de facto leader when it comes to blogging systems. While more generally referred to as a content management system (CMS), WordPress’ forte is blog management. Seeing how popular it is, most web developers are likely to encounter WordPress sometime in their careers, if they haven’t already.

In today’s WordPress tutorial, we aim to rectify that, by explaining what WordPress .htaccess file is, what it does, and show you how to create it.

What is the .htaccess file?

If you’re still dumbfounded about the .htaccess file, there is a good chance you’re hearing about it for the first time. There is a good reason for that; the .htaccess file is hidden by default in your project’s root directory. That is if it exists at all, which isn’t always the case.

The .htaccess file isn’t something specific to WordPress. In fact, any site that uses Apache’s Web Server can use the .htaccess file. The file itself is a configuration file for the server. The web server looks for the .htaccess file whenever it is launching the website and executes it if the file exists in the projects root directory.

The purpose of the .htaccess file is to reconfigure specific settings of the Apache Web Server. Thus, it can prove to be useful when toggling certain features of the server on or off. For instance, a typical use-case of the .htaccess file is to create redirects from non-www to www URLs and vice versa. Other uses include setting privileges for certain files, blocking bots or adding MIME types. It is particularly beneficial for taking care of security settings of your WordPress. These features come in handy during WordPress development, as you will have to configure some of these settings best suited to your needs.

How to Create Default WordPress .htaccess file

When you download, and install WordPress on Apache web server, by default it should come with a .htaccess file. This file is hidden, so to see it, you will have to enable the ‘Show Hidden Files’ option of your file system. We have a detailed tutorial showing how to locate .htaccess file on different systems here. But in some rare instances, your WordPress installation may not contain the .htaccess file or it was deleted unintentionally. If that’s the case, you are advised to create the .htaccess file manually.

Instructions below show how to create .htaccess file on Hostinger File manager. However, the process is similar or identical on cPanel. You can also create .htaccess file on your computer and upload it to web server using FTP client.

To create the .htaccess file using Hostinger file manager, simply navigate over to the root directory of your WordPress installation. Usually, this directory is named public_html. Once inside, create a new text file, and name it .htaccess.

Create Default WordPress .htaccess File

Open the file in any text editor. The .htaccess file contains a few lines of code which determines the default settings of the web server. The default WordPress .htaccess file looks like this:

Simply copy this code, and paste it in the newly created .htaccess file. Save the file and exit.

Default WordPress .htaccess Code

Congratulations! You have created your own .htaccess file. Now visit your WordPress website to make sure it’s working properly as incorrect .htaccess configuration can often lead to 500 internal errors).

Conclusion

The .htaccess file is mandatory for WordPress to work properly. It can provide a handle on additional features of the web server, especially as they pertain to security settings such as preventing spamming, blocking bad bots etc.

In this tutorial, you:

  • Learned more about the .htaccess configuration file and its uses
  • Saw how to create your own .htaccess file if absent from the WordPress installation
  • Add the relevant code to make the file operational

Now that you are somewhat familiar with the WordPress .htaccess file, you can move on to further exploring what is possible with it, for the betterment of your WordPress project.

Add Comment

Click here to post a comment

Join thousands of subscribers worldwide

and get awesome deals & the newest tutorials to your email

Please wait...

Thank you for sign up!

More in WordPress Tutorial
How To Fix WordPress Missed Schedule
How To Fix WordPress Missed Schedule

Close