WordPress – The most widely used Content Management System (CMS) in today’s internet realm – due to its popularity, is an incredibly attractive target for hackers. .htaccess is the most essential file for any website. Also, you can do a lot of things using the WordPress .htaccess file. You can restrict your website access. Additionally, It can be placed in any folder of the website to change the behavior of that folder.
As you’re aware, .htaccess is the control room of your whole website. Even a single misspelt dot (.) can destroy your complete website. So, before making any changes, back up your .htaccess file to an offsite location.
So, here we go!
By default, every web hosting has .htaccess file in the root directory. If it is not available, you can create one by opening Notepad and saving it with the name “.htaccess”. Be sure it’s not “htaccess”, its “.htaccess” and set “Save as type” to “All files”. Upload it to the root directory of your WordPress hosting server.
1. Protect .htaccess
.htaccess has the ability to control your whole website. Thus, it is important to first protect this file from unauthorized users. By using the snippet below, you can restrict access to unauthorized users. But, you can edit the file from FTP and your hosting.
Just copy and paste the snippet below into your .htaccess file.
2. Protect wp-config.php
In WordPress, wp-config.php is the file where your hosting, database and other important credentials are saved. Therefore, it is also required to restrict unauthorized access to this file. Copy and paste lines of code below, in your .htaccess file.
3. Protect /wp-contents/
Wp-contents is the folder in your WordPress directory that contains files of your themes, plugins, media and cached files. So, this directory is the main target for hackers and spammers. Create a separate .htaccess file. Copy and paste the snippet below, in that file.
Now, upload it to “www.yourwebsite.com/wp-contents/” folder.
4. Protect Include-Only files
There are some areas in WordPress that never have to be accessed by the user. It’s better to block access to those files. Also, you can place blocks by adding the snippet below, into your .htaccess file.
5. Limit Access to WordPress Admin Panel
What if someone gets access to your Admin Panel? This is another entry point for hackers to destroy your website. Just in case, if anyone gains access to the admin panel, he can do almost anything to your website. So, to get rid of such attempts, you can provide admin access to specific IP’s only. Create another .htaccess file by pasting the snippet below and upload it to “www.yourwebsite.com/wp-admin/” folder.
Don’t forget to change “184.108.40.206” to your own IP address. You can easily get your IP by visiting “What is my ip”. If you’ve got more than one moderator, you can also add more IP’s like this.
allow from 220.127.116.11 18.104.22.168 22.214.171.124
6. BAN Someone from Your Website
If you know someone is abusing your website, continuously spamming or launching hacking attempts, you can get his IP from your WordPress Admin Panel and add that IP to your .htaccess file to completely restrict access to your website. Just copy & paste the snippet below into your .htaccess file and he’ll not be able to access your website. Be sure to replace the IP address of that spammer.
7. Disable Directory Browsing
Unauthorized access to your files and folders can be a major security risk.
Thus, by adding the snippet below into your .htaccess file, access to your directories will be disabled.
# disable directory browsing
Options All -Indexes
8. Redirect a URL
A 301 error tells search engines that a URL has been permanently moved to another new location. You can redirect that old URL to the new one by using .htaccess. Moreover, this is not limited to URLs only, you can redirect a folder, page or even a complete website. You just have to add the few lines of code below, to your .htaccess file.
The first step to secure your WordPress website is your hosting. Sign up on secure Managed WordPress Cloud hosting. Then, you’ve got to secure it manually by implementing the above-mentioned tricks.
Looking for better performance and security?
To move to the next step for complete prevention from different kinds of attacks, there are a number of Plugins available on the WordPress repository. Some of the most popular ones are:
That about covers it for now. I hope you found this post informative. Implement these tricks on your WordPress site, and then test your security or you can follow these 10 WordPress security issues & how to fix them. Let me know if you have any questions or concerns, and I’ll get back to you.
Thank you, For great security tutorials on wordpress