What WordPress redirect malware is
Redirect malware, often called the “WordPress redirect virus”, is code an attacker adds to your site to send your visitors somewhere else: scam pages, fake prize pages, gambling sites, adult sites, or pages that push malicious browser notifications. The attacker gets paid for every visitor delivered. Your site is just the traffic source.
It’s one of the most common infections I clean, and one of the most frustrating for owners, because it’s designed so that you don’t see it.
Why the redirect only happens sometimes
A redirect that hit every visitor would be reported and removed within hours. So most redirect malware is conditional. Before redirecting, it checks things like:
- Are you logged in? Admins are skipped, so the owner never notices.
- Have you been here before? It sets a cookie on the first visit and leaves you alone afterwards.
- What device are you on? Many redirects only target phones.
- Where did you come from? Visitors arriving from Google, Bing, or Facebook are redirected; direct visits are not.
- What time is it, or which country are you in? Some only fire at certain hours or for certain regions.
That’s why “I checked and it’s fine” means very little with this kind of infection.
Some versions also hijack the admin area: wp-login.php or wp-admin suddenly redirects to another domain, so you can’t even log in to fix it. That’s still the same infection, and still fixable without the dashboard.
How to check for a redirect yourself
- Use a phone on mobile data (not your Wi-Fi), in a private or incognito tab.
- Search Google for your site’s name and click your own result.
- Try a couple of inner pages, not just the homepage.
If you have a terminal, you can also see exactly what different visitors receive:
# Arriving from Google on a phone
curl -sIL -A "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 Mobile/15E148" \
-e "https://www.google.com/" https://example.com/ | grep -i "^location"
# Google's crawler
curl -sIL -A "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" https://example.com/ | grep -i "^location"
Any Location: pointing to a domain that isn’t yours is a server-side redirect. Note that JavaScript redirects won’t show up here: they happen in the browser after the page loads, so the phone test is still important.
Where redirect malware hides in WordPress
Redirects can be triggered from many places, and an infected site often has two or three of them at once. Removing one and missing the others is the most common reason “the redirect came back”.
| Location | What it usually looks like |
|---|---|
.htaccess files |
RewriteCond rules checking HTTP_REFERER or HTTP_USER_AGENT, followed by a RewriteRule to another domain |
| Theme files | A few lines added to functions.php, header.php or footer.php that print a script for logged-out visitors |
| Plugins | Injected code in a real plugin, or a fake plugin with a believable name |
| The database | A <script> tag added to posts, widgets, or theme settings, or a changed siteurl / home value in wp_options |
| JavaScript files | Obfuscated code appended to the end of a legitimate .js file in your theme or a plugin |
| Server settings | An auto_prepend_file line in .user.ini or php.ini that runs a malicious file before every page |
How I remove redirect malware
- Reproduce the redirect using the same conditions your visitors have (device, referrer, first visit), so I know exactly what to look for and can confirm it’s gone later.
- Trace it to the source. I follow the redirect back from the browser to the code that produced it: a script tag, a PHP function, an
.htaccessrule, or a database value. - Check every other hiding place in the table above, because there’s usually more than one.
- Find the backdoor and the entry point. The redirect is the payload. The backdoor is what lets the attacker put it back. I remove both and fix the vulnerable plugin, theme, or password that let them in.
- Verify with the same mobile, search-referrer, and crawler tests, then help you request a Google review if the site was flagged.
A typical case: a store owner hears from customers that the site “goes to a lottery page” on their phones. The owner can’t reproduce it, and two scanners report the site as clean. The cause turns out to be a short script stored in the database, inside a theme option, that only loads for mobile visitors arriving from search engines. A second copy sits in a fake plugin called something like “wp-cache-helper”, which re-adds the script whenever it’s removed. Cleaning the database alone wouldn’t have lasted a day. Removing both, then updating the outdated page builder plugin that let the attacker in, fixed it for good.
After the redirect is gone
- If Google flagged the site, request a review in Search Console under Security issues. Malware reviews usually finish within a few days.
- Reset passwords and security keys so any stolen sessions stop working.
- Keep an eye on it for a few weeks. If the same redirect returns within a month, my guarantee covers it.
Redirects are just one kind of infection. If your site shows other symptoms too, see my full WordPress malware removal service or what to do when your WordPress site is hacked.