WordPress site redirecting to spam? How to find and remove it

A customer tells you that your website sent them to a gambling site, a page selling pills or a “you have won a prize” page. You open your site and it looks normal. You log in and the dashboard looks normal too.

This is one of the most common hacks on small WordPress sites. It is called a redirect hack. This guide explains why you often can’t see it, how to check for it, where the bad code usually hides, and how to remove it so it does not come back.

Why you can’t see the redirect

Redirect hacks are built to stay hidden from the owner. The bad code checks who is visiting before it sends anyone away. It often only redirects:

  • visitors on a phone, not on a computer
  • visitors who arrive from Google, not people who type your address
  • the first visit from each device, so a second try looks fine
  • visitors who are not logged in to WordPress

So the owner, who is logged in on a laptop and types the address, sees a normal site. A customer who taps your site in Google on their phone lands on spam. That is why many owners first hear about it from a customer, or from a Google warning.

First, rule out a normal redirect

Not every redirect is a hack. Check these before you assume the worst:

  • A redirect plugin. If you or your web designer use a plugin to send old pages to new ones, a wrong rule can send people to the wrong place. It will send them to another page on your own site or a site you know, not to spam.
  • The site address settings. In Settings > General, check that “WordPress Address” and “Site Address” both show your own domain. If either shows a domain you don’t know, that is a hack.
  • An expired domain. If your domain expired, visitors may see a parking page full of ads. Check the renewal date with your domain company.

If visitors land on gambling, adult, pill, crypto, fake prize or fake shop pages, treat it as a hack.

How to check if your site is redirecting

You can do these checks in about 10 minutes:

  1. Use your phone on mobile data. Turn off Wi-Fi, open Google, search for your business name and tap your site in the results. Try two or three different pages.
  2. Use a private window on your computer. Open a private or incognito window, search for your site in Google and click the result. Being logged out matters.
  3. Search Google for site:yourdomain.com (with your own domain). Look for pages you never made, or titles in other languages. Our guide on the Japanese keyword hack covers this sign.
  4. Check Google Search Console. Open Security & Manual Actions > Security issues. Google lists harmful content it has found on your site there.
  5. Run a free online scanner. It checks your site from the outside, the way a visitor sees it. A clean result does not prove the site is clean, because some redirects hide from scanners too.

If Chrome shows visitors a red screen with “Deceptive site ahead”, read our guide on the Deceptive site ahead warning as well. For the other signs of a hack, see Is my WordPress site hacked?

Where the redirect code usually hides

The redirect is rarely in one place. Attackers usually add it in several spots, so that deleting one copy does not stop it. Common places:

  • The .htaccess file. Rules that send visitors from Google or from phones to another site.
  • Theme files. Code added to files like header.php or functions.php, or to the theme’s JavaScript files.
  • WordPress core files. Code added to files like index.php or wp-config.php.
  • The database. Scripts hidden inside posts, pages, widgets or settings. The site address settings can also be changed here.
  • A fake plugin. A plugin with a normal-looking name that you never installed. Some hide from the plugin list.
  • The uploads folder. Code files hidden among your images. Only images and documents belong there.

On top of the redirect, attackers usually leave a backdoor: a hidden file or a hidden admin user that lets them back in.

Why it keeps coming back

Many owners delete the code they find, or install a security plugin and run one scan. A few days later the redirect is back. This happens for three reasons:

  • One copy of the code was removed, but others were missed.
  • The backdoor is still there, so the attacker comes back and adds the code again.
  • The way in is still open. On small business sites it is usually a plugin or theme that was not updated, or a weak or reused password.

A proper fix deals with all three.

How to remove the redirect hack

Work through these steps in order.

Step 1. Make a copy of the site as it is now

Back up the files and the database before you change anything. This copy is for checking what happened, not for restoring.

Step 2. Clean the site

  1. Scan the files and the database with a malware scanner, then check the results by hand.
  2. Restore the last clean backup from before the hack, or rebuild from clean parts: fresh WordPress files, and your theme and plugins reinstalled from their original source.
  3. Replace the .htaccess file with a clean WordPress default.
  4. Check the uploads folder and remove any code files.
  5. Check the database for scripts in posts, pages, widgets and settings, and for admin users you don’t know.
  6. Check that “WordPress Address” and “Site Address” show your own domain.

Redirect hacks can sit unnoticed for weeks. If your backups only go back a short time, check that the backup you restore is really from before the hack.

Step 3. Close the way in

Find out how the attacker got in. Update or replace the plugin or theme they used, and remove plugins and themes you don’t use. If you skip this step, the redirect usually returns.

Step 4. Change every password

Change the passwords for every WordPress admin user, your hosting account, the database and FTP. Turn on two-factor login for WordPress and for your hosting account.

Step 5. Scan again and test like a visitor

Run the scan again. Then repeat the phone and private window checks from above, on several pages, over a few days.

Step 6. Clear the warnings

If Google flagged your site, ask for a review in Search Console under Security issues once the site is clean. If your host suspended the site, tell them what you fixed and ask them to check it again.

How to stop it happening again

  • Keep WordPress, your theme and your plugins updated.
  • Remove plugins and themes you don’t use.
  • Use strong, unique passwords and two-factor login.
  • Keep daily backups stored away from your hosting, kept long enough that you have a clean copy to go back to.
  • Run a firewall and a daily malware scan, so a hack is found early.
  • Check your site on your phone, from Google, now and then.

Need help removing a redirect hack?

If you would rather not do this yourself, we can do it for you. Hacked Site Rescue starts from €149. We check your site first and confirm the price before we start. Then we restore a clean copy, close the way in, change your passwords, scan again and help you clear any Google warning.

Get help with a hacked site

To stop it happening again, our WordPress care plan costs €29 a month plus tax. It includes daily backups kept for 50 days, safe updates, a firewall, daily malware scans and vulnerability checks every 6 hours. If your site is hacked after 30 days on the plan, we get it back online at no extra cost.

Comments

Leave a Reply

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