WordPress redirect hack: remove spam redirects
WordPress redirecting visitors to spam or scam sites? Learn where the hack hides and the safe steps to contain it. Call (804) 375-4450.
At a glance
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.
Updated November 29, 2026
- 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
On this page
- What this error means
- Common causes
- Safe steps to try
- How to tell which cause you have
- What not to do
- When to stop and call someone
- How we fix it
- What a clean .htaccess looks like
- Useful checks if you have WP-CLI
- Which test shows which redirect?
- Worked example: redirects only from Google
- After the clean-up: prevention checklist
- FAQ
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.
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.
- Back up everything now,
files and database. Label it as infected; do not use it as a clean restore point.
- Change every password
WordPress admins, hosting, SFTP, database, and the email on the accounts. Do it from a clean computer.
- Check Users
Delete only admin accounts you are certain are not real, after noting their details.
- 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. - Update everything,
and remove plugins and themes you do not use. Reinstall fresh copies of the rest from official sources.
- Check Google's view
In Search Console, look at Security issues and at how Googlebot sees your pages.
- 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.
- Scan with a reputable security scanner
and keep its report.
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
12-hour clean-up target, 30-day reinfection cover.
Read more02Hacked site guideThe whole recovery, step by step.
Read more03Emergency support15-minute response, pay-only-if-fixed rescue.
Read moreOur 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. In an emergency, emergency support responds within 15 minutes, and rescue work is pay-only-if-fixed. You can also post a project.
What a clean .htaccess looks like
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:
# 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 WordPressKeep 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:
wp core verify-checksums
wp plugin verify-checksums --all
wp user list --role=administratorThe 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
A person reads it, any hour, and the clean-up carries 30-day reinfection cover.
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.
Link to this answerWill restoring a backup remove it?
Only if the backup predates the infection and you also close the way in. Otherwise it returns.
Link to this answerDo you give a guarantee after clean-up?
We include 30-day reinfection cover on malware clean-up.
Link to this answerHow 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.
Link to this answerWhy 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.
Link to this answerIs 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.
Link to this answerWhat 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.
Link to this answerWhat 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.
Link to this answerCan 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.
Link to this answerShould 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.
Link to this answerMy 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.
Link to this answerCan 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.
Link to this answerHow 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.
Link to this answerWho 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.
Link to this answerWant an engineer on it?
Tell us what is wrong in plain words. A person reads it, today.