Skip to content
Home » What is a .htaccess file? How it works in WordPress

What is a .htaccess file? How it works in WordPress

In this article, I will introduce you to a .htaccess file? Explain how it works and how to edit it. From there, you can find tips on how to use the .htaccess file better.

Keeping a site secure is one of the important tasks of every administrator.

While WordPress is one of the biggest CMS available today, hackers will pay more attention to you.

So how to secure your WordPress site. Happily, there are many ways without being your coder or developer.

You can leverage the power of the .htaccess file to increase WordPress security.

What is a .htaccess file?

The .htaccess file stands for “Hypertext Access”, it is a configuration file on the Apache webserver, it is used in a lot of WordPress sites.

For simplicity, .htaccess is a file that controls how to access a file in a directory.

This is a powerful tool to improve security and performance on WordPress.

Through just a few small changes, you can do a lot of things like block users, create redirects, block attacks, restrict access to certain areas of the website…

How to Edit .htaccess File

By default, the .htaccess file is available when WordPress is installed. Normally you will find it right in the root directory of WordPress. It contains only one file and does not contain any other file or extension.

Just open it with Notepad or Notepad++ or any similar software

A basic .htaccess file would look like this.

Note: You must not add or edit any code in paragraphs #BEGIN and #END. It is best to add a new paragraph below it.

After adding some code, don’t forget to save it. If you put in a lot of different codes, don’t add them all at once.

Turn one by one, if you encounter an error you will know which code fixed it.

But in some cases, you won’t be able to see it for editing.

Why can’t you find the .htaccess file?

A period before the file name indicates that it is a hidden file. If you are accessing the server via FTP client then sometimes you will not be able to see it

Because it is hidden, you will now have to select “Force to show hidden files”.

But you still don’t see the .htaccess file, even if it has to be turned on and hidden…

The most common reason is that your website has not yet created an .htaccess file. By default, WordPress will have this file on the first set of Permalinks » Permalinks.

Permalinks

All you have to do is click on the Save Changes button on the permalinks screen and WordPress will create it in the root of your website.

In some cases, WordPress is not allowed to create the .htaccess file because there is no write permission.

In that case, WordPress will show you a notification at the bottom of the Settings » Permalinks screen, informing

you that the .htaccess file is not writable.

If you set the permalink to use settings other than the default, it will also show you the code you need to paste into the .htaccess file.

WordPress shows the message that the .htaccess file is not writable.

Just copy the following code and paste it in notepad and save it as .htaccess. then upload it to wordpress root directory

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule. /index.php [L]
</IfModule>
# END WordPress

If you get an error while uploading that file, you will need to change the file permissions. Let’s assume that all your WordPress files are under /home/domain name/public_html/ .

This makes public_html your root directory. You need to go to its parent directory and right-click on the public_html directory.

Choose File Permissions, the file will open a file permissions dialog. You need to enter 755 for that dialog box and then try to upload your .ht-access file to the public_html directory.

Find .htaccess File on Hosting with Cpanel

If you are using hosting with Cpanel then everything is quite simple. First, log in to your hosting account and select File Manager in the Files section

You should see .htaccess file in public_html directory
If it doesn’t, select Settings (in the upper right corner of the screen) and select Show hidden files.

If your hosting does not have or does not have the file. Icon + File Left corner or Left mouse location Select new file. Enter the name of the .htaccess file and click Create New File.

I hope this article helped you to find or create .htaccess file on WordPress website.

If you’re just getting started with WordPress, don’t forget to check out the beginners guide, here are specific instructions for those new to WordPress.

Let me know if you have any questions or feedback in the comments below.

Leave a Reply

Your email address will not be published. Required fields are marked *