# WordPress redirect hack: remove spam redirects

URL: https://wp24x7.com/fix/wordpress-redirect-hack/
Updated: 2026-11-29
Type: page

> A WordPress redirect hack quietly sends some visitors, often those arriving from Google or on phones, to spam, scam or pharmacy sites. Back up, change every password, then check .htaccess, plugins, users and injected scripts. If the cause is not obvious, stop and have the infection cleaned properly. WP24x7 offers malware clean-up with 30-day reinfection cover.

## Key facts

- For: owners whose visitors are sent to spam or scam sites
- Usual causes: outdated plugin, weak passwords, nulled plugins, injected code
- First steps: backup labelled infected, rotate passwords, inspect .htaccess
- Clean-up: malware removal targets 12 hours, with 30-day reinfection cover
- Emergency response: 15 minutes with emergency credits; rescue is pay-only-if-fixed
- Start: call the help desk or post a project

A redirect hack sends some visitors, often only those from Google or on phones, to spam, scam or pharmacy sites. **Take a backup, change passwords, and check .htaccess, plugins, users and injected scripts. If the cause is not obvious, stop and get the infection cleaned properly.**

> **Contain first**
Back up and label it infected, change every password from a clean computer, and do not restore an old backup until you know the entry point. Reinfection is common when one door stays open.

## What this error means

Your site has been altered so that it quietly forwards people elsewhere. Because the owner often sees nothing wrong, the first sign may be a Google warning, a drop in traffic, or a customer complaint.

## Common causes

| Cause | How it shows | What to check |
|:--|:--|:--|
| Outdated or vulnerable plugin or theme | Hack began after a disclosed flaw | Update, remove unused |
| Stolen or weak passwords | Unknown admin or odd logins | Rotate all passwords |
| Pirated (nulled) plugins or themes | Hidden code in files | Replace from official sources |
| Malicious rules in `.htaccess` or PHP | Redirect before page loads | Inspect `.htaccess`, theme files |
| Injected JavaScript | Redirect after page loads | Posts, widgets, database |
| Compromised neighbour account | Other sites on the account infected | Ask the host |

## Safe steps to try

These steps contain the problem. Full clean-up is a separate job.

1. **Back up everything now,** files and database. Label it as infected; do not use it as a clean restore point.
2. **Change every password:** WordPress admins, hosting, SFTP, database, and the email on the accounts. Do it from a clean computer.
3. **Check Users.** Delete only admin accounts you are certain are not real, after noting their details.
4. **Inspect `.htaccess`.** Download it and look for rules mentioning unfamiliar domains, user-agents or referrers. Replace it with the standard WordPress block rather than deleting it; do not remove `wp-config.php`.
5. **Update everything,** and remove plugins and themes you do not use. Reinstall fresh copies of the rest from official sources.
6. **Check Google's view.** In Search Console, look at Security issues and at how Googlebot sees your pages.
7. **Look at modified files.** In the hosting panel, sort files by modified date and review anything recent you did not change. Do not run mass permission changes.
8. **Scan with a reputable security scanner** and keep its report.

_Scanning the site for injected redirects_

## How to tell which cause you have

Redirect hacks vary, so gather evidence rather than guessing. Test the site in a private window on a phone, and from a Google search result, because many hacks only fire for those visitors. Check the browser's network panel to see where the first redirect comes from. A redirect from the server before the page loads points at `.htaccess` or server config. A redirect after the page loads points at injected JavaScript.

Compare your plugin and theme folders with fresh downloads from official sources if you can; differences in files that should be identical are a strong sign. Look at scheduled tasks and the Users list for entries you did not create. Check whether your host or your scanner reported specific files. The more evidence you collect, the faster a professional can clean up.

## What not to do

Do not rely on a plugin that only hides the redirect, and do not simply restore an old backup without closing the entry point. Do not delete `wp-config.php` or run mass permission changes. Do not ignore customers' reports; they may be the only way you see the problem.

## When to stop and call someone

Stop if redirects return after cleaning, if you find encoded PHP or files you cannot explain, if your site is flagged by Google, or if customer data may be involved. Reinfection is common when one entry point is left behind, and tidy-ups that only treat symptoms waste time.

## How we fix it

- **Malware removal** 12-hour clean-up target, 30-day reinfection cover. [Read more](/wordpress-malware-removal)
- **Hacked site guide** The whole recovery, step by step. [Read more](/hacked-wordpress-site)
- **Emergency support** 15-minute response, pay-only-if-fixed rescue. [Read more](/wordpress-emergency-support)

Our [malware removal](/wordpress-malware-removal) service clears infections, with a 12-hour clean-up target, and we give 30-day reinfection cover. For the whole recovery, see [hacked WordPress site](/hacked-wordpress-site). In an emergency, [emergency support](/wordpress-emergency-support) responds within 15 minutes, and rescue work is pay-only-if-fixed. You can also [post a project](/post-project).

## What a clean .htaccess looks like

> **Replace, do not delete**
Swap `.htaccess` for the standard WordPress block and keep a copy of the suspicious file. Never remove `wp-config.php`.

A standard single-site WordPress `.htaccess` is short. If yours has many lines of rewrite rules mentioning other domains, user-agents or referrers, that is suspicious. The default block is:

```apache
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
```

Keep a copy of the suspicious file before replacing it. Other plugins may legitimately add their own blocks, so compare against what each plugin documents. Note that replacing `.htaccess` alone rarely ends an infection, because attackers usually leave a second way back in.

## Useful checks if you have WP-CLI

These are read-only and safe to run:

```bash
wp core verify-checksums
wp plugin verify-checksums --all
wp user list --role=administrator
```

The first two compare files with the official copies and report anything modified or unexpected. The third lists administrators so you can spot an account you did not create. Plugins not hosted on wordpress.org cannot be verified this way, so a missing result is not proof of a problem.

## Which test shows which redirect?

| Test | What it tells you |
|:--|:--|
| Private window on a phone from a Google result | Whether the hack targets search visitors |
| Browser network panel | Where the first redirect comes from |
| `wp core verify-checksums` | Modified core files |
| Administrator list | Accounts you did not create |
| Search Console security issues | Whether Google already flagged the site |

## Worked example: redirects only from Google

Imagine an owner who types the address and sees the site normally, while customers say clicking from Google lands them on a pharmacy page. The cause is a rule that fires only when the referrer is a search engine. The giveaway is that a test from a search result on a phone reproduces it, while the owner's own visit does not. The place to look is the `.htaccess`, then theme files such as `header.php` and `functions.php`, then injected scripts. Because the owner never sees it, the problem can run for weeks, which is why a Google security warning is often the first sign.

## After the clean-up: prevention checklist

- [ ] All plugins and themes updated, unused ones removed
- [ ] Administrator list reviewed, passwords changed, two-factor sign-in on
- [ ] Hosting, SFTP and database passwords rotated
- [ ] Off-site backup taken after cleaning, labelled clean
- [ ] Google Search Console checked and a review requested if flagged
- [ ] Monitoring for file changes and uptime in place
- [ ] Cause identified, not just symptoms removed

**Redirects on a live site?**
A person reads it, any hour, and the clean-up carries 30-day reinfection cover.
[Call the help desk](tel:+18043754450)
[Post a project](/post-project)

## Frequently asked questions

### Why do I not see the redirect myself?

Many redirect hacks hide from logged-in admins and from direct visitors, and fire only for people arriving from Google or on mobile.

### Will restoring a backup remove it?

Only if the backup predates the infection and you also close the way in. Otherwise it returns.

### Where is the code usually hidden?

Common places are .htaccess, theme and plugin files, the wp-content/uploads folder, injected JavaScript in the database and rogue admin users.

### Do you give a guarantee after clean-up?

We include 30-day reinfection cover on malware clean-up.

### How can I test for a redirect that only some visitors see?

Open the site from a Google search result in a private window, and on a phone using mobile data. Many redirects only fire for search and mobile visitors.

### Why do I not see the redirect myself?

Many redirect hacks fire only for visitors arriving from search engines, on phones or for first-time visitors, and skip logged-in admins. Test in a private window on a phone, starting from a Google result, to see what customers see.

### Is restoring an old backup enough to remove the hack?

Not by itself. Without closing the entry point, such as an outdated plugin or a stolen password, the site is infected again. Restore only after finding how the attacker got in, and change every password first.

### What is the difference between a server-side and a JavaScript redirect?

A redirect that happens before the page loads points at .htaccess or server configuration. A redirect after the page loads points at injected JavaScript in posts, widgets, theme files or the database. The browser network panel shows which one it is.

### What does a normal WordPress .htaccess look like?

A standard single-site file is short, between the BEGIN WordPress and END WordPress markers, with a few rewrite rules. Many lines mentioning other domains, user-agents or referrers are suspicious. Keep a copy of the suspicious file before replacing it.

### Can WP-CLI check whether my files were modified?

Yes. wp core verify-checksums and wp plugin verify-checksums --all compare files with the official copies and are read-only. Plugins not hosted on wordpress.org cannot be verified this way, so a missing result is not proof of a problem.

### Should I delete admin users I do not recognise?

Only accounts you are certain are not real, and note their details first. An extra administrator is a common sign of a compromise and also evidence a professional can use to trace the entry point.

### My site is flagged by Google. What now?

Clean the infection first, then request a review in Search Console. Requesting a review before the clean-up completes usually fails. Our blacklist removal page explains the process, and malware removal covers the clean-up.

### Can nulled plugins cause redirect hacks?

Yes. Pirated plugins and themes often carry hidden code. Remove them and install fresh copies from official sources or buy a licence. Do not reuse files from the infected site.

### How can I stop it coming back?

Update everything, remove unused plugins and themes, rotate hosting, SFTP and database passwords, turn on two-factor sign-in and keep monitoring for file changes and uptime. Take a clean off-site backup after cleaning.

### Who can clean it for me?

Our malware removal service clears infections with a 12-hour clean-up target and 30-day reinfection cover. In an emergency the support line responds within 15 minutes, and rescue work is pay-only-if-fixed.
