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. You can do a lot of things using the WordPress .htaccess file. You can restrict your website access. It can be placed in any folder of the website to change the behavior of that folder.
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.
.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.
|<files ~ "^.*\.([Hh][Tt][Aa])">|
|deny from all|
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.
|deny from all|
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.
|Deny from all|
|<Files ~ ".(xml|css|jpe?g|png|gif|js)$">|
|Allow from all|
Now, upload it to “www.yourwebsite.com/wp-contents/” folder.
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.
|RewriteRule ^wp-admin/includes/ - [F,L]|
|RewriteRule !^wp-includes/ - [S=3]|
|RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]|
|RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]|
|RewriteRule ^wp-includes/theme-compat/ - [F,L]|
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.
|# Limit logins and admin by IP|
|<Limit GET POST PUT>|
|deny from all|
|allow from 188.8.131.52|
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
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.
|<Limit GET POST>|
|deny from 123.456.78.9|
|allow from all|
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
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.
|Redirect 301 /oldpage.html http://www.yourwebsite.com/newpage.html|
|Redirect 301 /oldfolder/page2.html /folder3/page7.html|
|Redirect 301 / http://www.mynewwebsite.com/|
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.
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 your interest on . Please fill out the form below and send it to us.