If visitors are telling you that your WordPress site is redirecting them to spam, a gambling site, a fake pharmacy, or a page full of malware warnings, you're likely dealing with a WordPress redirect hack. And if you checked your site yourself and everything looked fine, that doesn't mean they're wrong.
Redirect hacks are one of the most disruptive WordPress infections because they're designed to be invisible to you while harming the visitors who find you through Google. Your site looks normal when you type in the URL directly. It looks normal when you're logged in as an admin.
But when a first-time visitor clicks through from a search result on their phone, they get sent somewhere else entirely.
Redirect code is one of the first things we look for when a hacked site comes to us, and it's among the most damaging WordPress security threats from a business perspective. A site redirecting to spam destroys visitor trust immediately, and a Google warning, if one follows, can cost you search traffic until it's lifted.
What a WordPress Redirect Hack Actually Does
A WordPress redirect hack is malware that injects hidden code into your website's files, database or server configuration, causing visitors to be automatically sent to attacker-controlled spam or scam pages. The redirect is conditional, targeting specific visitors based on criteria like device type, referral source, or login status while staying invisible to site administrators.
The infection can live in multiple places: your .htaccess file, your wp-config.php, WordPress core files like wp-blog-header.php, theme files like header.php and functions.php, your database, the must-use plugins folder, or fake plugins that attackers create and activate on your site.
Typical destinations include pharmacy spam, fake dating sites, gambling portals, crypto scams, malware downloads and phishing forms. Newer campaigns also send visitors to fake browser updates or fake CAPTCHA pages that tell them to paste a command into their computer. Check Point reported one of these fake CAPTCHA campaigns running on about 2,000 hacked WordPress sites in August 2026.
The scale is real. Sucuri's 2024 SiteCheck report counted about 1.18 million infected websites found by its remote scanner, and malware and malicious redirects made up about three quarters of those infections.
In March 2025, GoDaddy's security team documented one of the longest-running campaigns, DollyWay. Over eight years it infected more than 20,000 WordPress sites, and more than 10,000 were still infected when GoDaddy published, generating around 10 million page impressions a month with redirect scripts that fed the VexTrio affiliate network, one of the largest known cybercriminal affiliate networks.
These aren't small, isolated incidents. Redirect hacks are an industry.
Why You Can't See It But Your Visitors Can
This is the part that trips up most site owners. You check your site, everything looks fine, and you conclude that the person complaining must be mistaken. But redirect hacks are engineered to avoid detection by the one person most likely to check: you.
How Conditional Redirects Stay Hidden
Modern redirect malware uses conditional targeting, meaning it only redirects certain visitors under specific circumstances. The infections we've cleaned up used more than one of these techniques at once.
| Technique | What It Does | Why You Miss It |
|---|---|---|
| First-visit only | Redirects new visitors, not returning ones | You've visited before so you see the normal site |
| Logged-in user exclusion | Skips admin and editor accounts | Site looks fine when you're logged in |
| Search engine referral only | Only redirects visitors arriving from a search engine | Direct visits work normally |
| Geographic targeting | Redirects visitors from specific countries | Your location may not be targeted |
| Device targeting | Redirects only mobile or desktop | You may be checking on the wrong device |
| Skips bots and scanners | Shows the clean site to monitors, scanners and SEO tools | Your tools report that everything is fine |
| Search engine crawlers only | Shows spam to Google's crawlers and the real site to people | Nobody sees it in a browser at all |
Logged-in user exclusion is one of the most common evasion techniques. WordPress admin users never see the redirect. Only logged-out visitors, your actual audience, get redirected. You literally can't see the problem while logged into your dashboard.
Search engine referrer targeting means the malware checks where the visitor came from. If they arrived from Google, Bing, or Yahoo, they get redirected. If you typed the URL directly into your browser, you see the normal site.
First-visit targeting sets a cookie or a flag in the browser on the initial visit and only redirects once. If you visit again, you see your normal site. This makes reproduction difficult, and it's why "I checked, and it looks fine to me" is such a common response from site owners dealing with an active infection.
Mobile-only targeting is another common variant. Some infections target mobile devices while skipping desktop browsers, since site owners typically test on desktop.
Scanner and crawler exclusion is the one that defeats automated checks. Some variants carry a list of known monitoring tools, malware scanners and SEO crawlers and show every one of them the clean site. Others do the reverse and show the spam only to search engine crawlers.
All of these techniques combined mean a WordPress redirect hack can run for weeks or months before anyone on your team notices. Usually, the first sign is a complaint from a visitor, a warning from Google Search Console, or your hosting provider flagging the account.

A Real Example From a Site We Host
We know how well this works because it happened on a site we host. Staff at a nonprofit told us their homepage had been replaced with a gambling page. It hadn't been, exactly. The site was showing its normal homepage to people and a spam page to Google's crawlers only.
The code went further than that. It carried a list of the tools that might catch it, including uptime monitors, malware scanners and SEO tools, and showed every one of them the clean site. A scan would have come back clean. The only reason anyone saw it was that the CDN cached the crawler's version and served it to real visitors.
The attacker didn't come in through a vulnerable plugin. A rogue admin account was created inside one of the site's admins' own logged-in sessions, and the attacker waited five days before planting anything. The cloak was live for about 17 hours. We had the site cleaned 21 minutes after the ticket came in, and Google re-crawled the clean homepage about 90 minutes after that.
The next day we went back through the server's access logs and found a second tool the attacker had installed that the first pass missed. Caught that fast, it did no measurable damage to the site's search traffic.
How to Confirm Your Site Is Redirecting
Because the redirect is built to skip you, checking the way you normally do proves nothing. Check the way a stranger would:
- Open your site in a private window, logged out.
- Try it on your phone, on mobile data rather than your office Wi-Fi.
- Search Google for your organization and click through from the result instead of typing the address.
- Search
site:yourdomain.organd look for pages or titles you don't recognize. - In Google Search Console, check Security Issues and Manual Actions, then run URL Inspection's live test on your homepage to see what Google actually receives.
If any of those shows something you didn't publish, treat the site as compromised, even if every other check looks normal. And if all of them look clean but a visitor swears they were redirected, believe the visitor. Some infections only fire once per person.
Where the Malicious Code Hides
Redirect malware doesn't live in just one place. That's what makes cleanup difficult. Miss one injection point, and the site reinfects itself.
Server Configuration Files
The .htaccess file is a common injection point because it operates at the server level, before WordPress even loads. The default WordPress .htaccess block is about 10 lines long. A legitimate file can be longer (caching rules and redirects add lines), so length alone proves nothing, but RewriteCond rules that check for search-engine referrers or mobile user agents, paired with RewriteRule directives pointing to outside domains, mean it's been compromised. Our guide to what a legitimate .htaccess redirect looks like helps you tell the difference. Once the site is clean, saving your settings under Settings, then Permalinks regenerates the standard WordPress block.
Attackers also inject malicious require, include, or eval statements into wp-config.php because it loads on every WordPress request. These often pull in remote malware files or execute obfuscated redirect code through eval(base64_decode(...)) calls.
Some servers read a .user.ini file, and an auto_prepend_file line in it runs a file of the attacker's choosing before every page. On the site in our example, that's how the live cloak was loaded.
WordPress Core Files
Some variants modify WordPress core files directly. Common targets include wp-includes/version.php, which loads early in the WordPress boot process, wp-blog-header.php, which serves as the entry point for all frontend requests, and wp-load.php, which loads the WordPress environment. The site in our example had a patched wp-blog-header.php sitting dormant as a backup.
Attackers also append malicious code to JavaScript files in wp-includes/js/, piggybacking on legitimate jQuery files. Core file integrity checks compare file hashes against WordPress.org originals and catch these quickly, but only if you're running them.
Theme, Plugin and Must-Use Plugin Files
Theme files like header.php, footer.php, and functions.php are favorite targets because they execute on every page load. The malicious code is typically obfuscated using base64_decode(), str_rot13(), or gzinflate() encoding, with variable names designed to resemble legitimate WordPress functions.
Attackers also create entirely fake plugins in your /wp-content/plugins/ directory with innocent-sounding names. These get activated and load on every request. DollyWay installed the real WPCode plugin, filled it with obfuscated malicious snippets, and hid it from the plugin list.
The /wp-content/mu-plugins/ folder deserves its own check. Must-use plugins load automatically, can't be switched off from the dashboard, and don't appear in the normal plugin list. The site in our example had a third delivery mechanism waiting there.
Database Injections
Malicious JavaScript or iframes can be injected directly into your wp_posts table, your widget content in wp_options, or your theme settings. Database injections are harder to detect manually because the malicious code is stored as serialized data mixed in with your legitimate content.
In some cases, attackers change your siteurl or home options in wp_options to redirect the entire site. They also create hidden administrator accounts for persistent access. In Sucuri's 2023 hacked website report, 55.2% of sites with database malware had at least one malicious admin user.
The Uploads Directory
Attackers place PHP files disguised with innocent names in /wp-content/uploads/, a directory that should contain only images, PDFs, and other media files. They blend in with legitimate upload handling, but they're backdoors that enable reinfection even after a partial cleanup. The same Sucuri report found that 49.21% of compromised sites had at least one backdoor.

How Redirect Hacks Get In
Understanding the entry vector matters because cleaning up a redirect hack without addressing how it got in guarantees reinfection.
Vulnerable plugins and themes are the most common entry vector. Patchstack counted 11,334 new vulnerabilities in the WordPress ecosystem in 2025, about 31 a day, and 91% of them were in plugins. Outdated plugins with known security flaws are the easiest path in for automated scanning bots, and those bots are scanning constantly. The risk is compounded when trusted plugins are compromised at the source, delivering malware through normal update channels, and cross-site scripting flaws can let an attacker plant a redirect script without ever logging in.
"You don't have to be on anyone's threat list. You don't have to be a target. You don't have to be controversial."
Bots scan IP ranges looking for any site running a vulnerable version of a popular plugin. Your organization's profile, your content, your audience: none of it matters to an automated scanner.
Core isn't immune either. In July 2026 a flaw in WordPress core itself, known as wp2shell, was patched and then exploited within days on sites that hadn't updated. Updating after the fact closes the hole but doesn't remove anything an attacker already planted. Patching is not cleanup.
Compromised credentials are the other common way in. Weak passwords, reused passwords, or credentials leaked in other breaches give attackers direct admin access without needing to exploit any vulnerability. Brute force attacks and user enumeration automate this process for sites without proper authentication hardening. Once they're in, a redirect hack is just a matter of time.
Hijacked sessions are the one most people don't think about. A password and even two-factor authentication protect the login, not a session that's already open. If someone takes over an admin's logged-in session, everything they do looks like that admin. That's how the attacker got in on the site in our example.
Insecure hosting environments also play a role. On shared hosting without proper account isolation, a compromised site on the server can spread infections to neighboring accounts. PHP execution enabled in the uploads directory, outdated server software, and missing file permission controls all widen the attack surface.
The redirect hack itself is the symptom. The root cause is almost always a gap in one of these areas.
Business Impact Beyond the Redirect
The redirect itself is damaging enough. Your visitors are being sent to scam sites, and your organization's reputation takes a hit every time it happens. But the downstream consequences can be worse than the infection itself.
Google Warnings
When Google detects a redirect hack, it can flag your site with a "This site may be hacked" label in search results or show a full-page "Deceptive site ahead" warning in Chrome. Firefox and Safari use Google Safe Browsing data too, so the warning follows your visitors across browsers.
Traffic falls hard once a warning is showing, and the warning doesn't go away the moment you clean up. You fix the whole site, then request a review in Search Console. Google says a review "can take from a few days to a few weeks."
Speed is what keeps you out of that position. The site in our example was cleaned within a day of the cloak going live, Google never flagged it, and its search traffic didn't move.
"It's not a wait-and-see game where you clean up afterwards. It's a multi-layer approach to keeping it from happening in the first place. And then if it does happen, acting insanely fast so you don't end up blacklisted."
Reputation and Trust
For nonprofits, associations, and advocacy organizations, the damage to trust can be harder to quantify but just as real. Members or supporters who encounter a redirect to a scam site may not come back. Even after the infection is cleaned, the experience lingers.

How to Fix a WordPress Redirect Hack
My position on this is clear: have professionals clean a hacked site, not DIY. If you need to fix a WordPress redirect hack, doing it properly is the difference between a one-time cleanup and a recurring nightmare. This is the work behind our malicious redirect removal for the sites we host.
"Infections are self-replicating. They compromise both files and the database. To think you're going to clean it up manually is a gamble."
The reason is straightforward. Redirect hacks install multiple infection points and backdoors across your files and database. If you find and remove the obvious redirect in your .htaccess file but miss the backdoor in your uploads directory and the hidden admin account in your database, the site reinfects itself from the pieces you missed.
DollyWay reinfected itself every time any page loaded, re-injecting its code into the site's active plugins and switching off a list of known security plugins.
We do the cleanup ourselves, and for sites we host it's included. The approach is the same every time: preserve a copy for evidence, work out how they got in from the server's access logs, remove every piece, then go back through the logs the next day and check again. That second pass matters. On the site in our example, it found something the first pass missed.
Security plugins have a built-in weakness: they run inside the WordPress install they're protecting. Research cited by Patchstack found that up to 14% of malware tampers with the most popular WordPress security plugin, and Sucuri has documented malware that edits Wordfence's own files to hide backdoors. That's one reason we rely on server-level scanning with Imunify360, which runs below WordPress where WordPress malware can't reach it.
The cleanup process follows a systematic approach:
- Stop the harm to visitors, with a maintenance page if needed
- Back up the infected site for forensic analysis
- Work out the entry point and every file the attacker touched from the server's access logs, then check the disk
- Replace all WordPress core files with fresh copies
- Reinstall plugins from scratch rather than trying to clean them
- Audit theme files, must-use plugins,
.user.ini, scheduled tasks and the database for injected code - Remove unauthorized admin accounts, end every logged-in session, reset every password and rotate the security keys
- Purge every cache, including the page cache and the CDN, so nobody keeps getting the infected version
- Verify the cleanup from multiple angles, including mobile user agents and search engine referrers, not just checking the site while logged in
- Go back the next day and do it again from the logs
After cleanup, the hardening steps matter just as much: updating everything, removing unused plugins and themes, setting proper file permissions, and disabling file editing through the WordPress admin. If the attacker came in through a session, have the people who log in scan their computers too. Without these steps, the same gap that let attackers in the first place remains open.
For a closer look at how cleanup, hardening, and ongoing monitoring fit together, see what professional security management includes.
The Overlap With Pharma Hacks
Redirect hacks and pharma hacks frequently co-occur. In the same Sucuri report, 28.19% of SEO spam infections involved malicious redirects. The same compromised access point that enables a redirect can also be used to inject spam keywords and links aimed at search engine crawlers. The site in our example was both at once: a crawler-only spam page that real visitors saw because it got cached.
If your site has a redirect hack, check for search spam as well. The cleanup needs to address both, or you'll end up with a second round of Google Search Console warnings after you think the problem is solved.
How We Prevent This for Our Clients
I'd love to tell you we've never had one of these. We have: the site above. What I can tell you is that across the 200+ sites we host, no infection has come in through our servers. The one cloaked spam case on a site we host came through an admin's own session, which no firewall can tell apart from the real person. Every layer we run is there because one layer is never enough.
Our defense starts at the edge, with Cloudflare Enterprise in front of every site we host. In one three-day window this November it blocked more than 330,000 requests aimed at those sites, about 110,000 a day. It stops known attack patterns and bad bot traffic before they reach the server. It doesn't stop everything, and nobody's firewall does.
On the server, Imunify360 runs on every server we host on. It blocks abusive IP addresses on its own and scans sites for malware overnight. On the day we checked, every site had been scanned within the previous ten hours, and across the roughly 150 production sites with malware protection it found zero infected files. Because it runs outside WordPress, malware inside WordPress can't switch it off.
Inside WordPress, our own must-use plugin blocks user enumeration on every site we host, so bots can't easily harvest admin usernames to guess against. Two-factor authentication is available on request.
We update plugins, themes and WordPress core every week, and every update is tested on a copy of the site first. In the last three months that came to more than 4,600 updates across 138 sites. When an update changed how a page looked, we held it for a person to review instead of pushing it live. That happened 30 times. (Here's why we don't rely on WordPress auto-updates alone.)
"Security is not an option. Anyone who guarantees you 100% security is a fool. What we guarantee is that we have the best tools, practices, and services in place, plus rapid response and recovery."
For plugin-borne infections, the difference between a site that gets redirect-hacked and one that doesn't usually comes down to whether someone is actively maintaining it or whether it's sitting there with an outdated plugin and no firewall. Sessions are the exception, which is why fast cleanup matters as much as prevention. For organizations that want to make sure their WordPress site isn't redirecting to spam or scam pages, our WordPress security services cover the full stack: edge protection, server-level scanning, tested weekly updates, and in-house cleanup.
What to Do Right Now
If you're reading this because your site is actively redirecting visitors, here are the immediate priorities:
- Don't try to fix it yourself by editing individual files. You'll likely miss injection points, and the infection will return.
- Take the site offline with a maintenance page to stop visitors from being redirected to malicious content.
- Change all passwords and end every session. WordPress admin, SFTP, hosting panel, and database, and log every user out.
- Check Google Search Console for security warnings. If your site is flagged, you'll request a review after cleanup.
- Get a professional cleanup. This isn't a job for manual file scanning.
- Purge your caches after cleanup, including any CDN, or visitors may keep getting the infected version.
- Have everyone who logs in scan their computer. A hijacked session can bring the attacker right back.
If you can, take a copy of the site before anyone starts deleting files; what to do in the first hour of WordPress malware removal explains why, with the mistakes we've made ourselves.
Free remote scanners like Sucuri SiteCheck can detect client-side redirect malware. But server-side and .htaccess redirects can be invisible to remote scanners, because the scanner's request doesn't match the targeting rules, and some infections keep a list of scanners to show the clean site to. A clean remote scan doesn't guarantee a clean site. The same limits apply to security plugins.
The Bottom Line
The fastest path from "my site is redirecting" to "my site is clean and protected" runs through a professional cleanup followed by proper hosting and maintenance. The WordPress redirect hack is the symptom. Ongoing security management is the cure.
FAQ
Why can't I see the redirect on my own site?
Redirect hacks are built to avoid detection by site owners. The malware checks whether you're logged in, whether you've visited before, what device you're using, and where you came from. If you're an admin browsing from your usual computer, you'll see the normal site every time. The redirect often fires only for new visitors coming from Google on a mobile device. That's why the first sign is usually a complaint from someone else.
Why does my WordPress site redirect only on mobile?
Some redirect malware checks the visitor's device and only fires on phones, because site owners usually check their own site on a desktop. To test it, open the site on your phone over mobile data, in a private window, and click through from a Google search result rather than typing the address.
Why does it only redirect when I click from Google?
Many variants check the referrer, meaning where the visitor came from. If the visit comes from a search engine, the redirect fires. If you type the address directly or use a bookmark, you see the normal site. Searching for your organization and clicking the result is one of the most reliable ways to reproduce it.
Will Google blacklist my site for a redirect hack?
It can, and that's one of the biggest risks. When Google detects that your site is sending visitors to spam or malware, it can label it in search results or show a full-page warning in Chrome, Firefox and Safari. Traffic drops sharply while that warning is up. After cleanup you request a review in Search Console, and Google says that can take from a few days to a few weeks. The faster the cleanup, the better the odds you never get flagged at all.
How long does Google take to remove a hacked site warning?
Google's guidance is that a security review can take from a few days to a few weeks after you request it in Search Console. Fix the whole site before you ask, because a partial fix won't clear the warning, and repeated requests while one is pending can slow things down.
How do I fix a WordPress redirect hack?
The honest answer is to have someone who does this regularly clean it, not to do it yourself. Redirect hacks leave several infection points and backdoors across your files, database and server configuration, and missing one brings the redirect back. We clean hacked sites in house, and for sites we host, cleanup is included. After cleanup, close the way in: update everything, change every password, end every logged-in session, and put proper security infrastructure in place.
Will a malware scanner find a redirect hack?
Not always. Remote scanners only see what the site chooses to show them, and some redirect malware keeps a list of known scanners, monitors and SEO tools and shows each of them the clean site. Server-level scanning and file integrity checks help, but a clean scan on its own doesn't prove a clean site.
Can my site still show the hacked version after it's cleaned?
Yes, if a cache is still holding the infected copy. Page caches, a CDN and visitors' browsers can all keep serving the old version. Purge every cache you control as part of the cleanup, then check again from a private window and a phone.
Can a security plugin prevent redirect hacks?
A plugin alone isn't enough. Security plugins run inside WordPress, so malware that gets in can sometimes tamper with the plugin itself; Sucuri has documented malware doing exactly that to Wordfence. A firewall at the network edge, like Cloudflare, blocks a lot of attack traffic before it ever reaches your server, and server-level scanning like Imunify360 adds a layer that runs completely outside WordPress. No single layer catches everything, which is why you want more than one.
How do redirect hacks get onto my site in the first place?
The most common entry points are outdated plugins and compromised credentials. Bots scan the internet constantly looking for WordPress sites running plugins with known vulnerabilities, and when they find one, the exploit and the malware deployment happen automatically. Weak or reused passwords are the other big vector, especially without two-factor authentication. A hijacked logged-in session can get around both, which is why ending every session is part of a proper cleanup. In shared hosting environments, one infected account on the server can sometimes spread to others.