WordPress Redirect Hack: How to Find and Remove It
Your WordPress site redirects visitors to spam? Here's where the malicious redirect hides and how to find and remove it — free and read-only.
One day your WordPress site works fine; the next, visitors click a Google result and land on a sketchy pharmacy, a betting site or a fake virus warning. That’s the WordPress redirect hack — one of the most common infections, and one of the most frustrating, because it often hides from you while hitting everyone else. Here’s how to find where it’s injected and remove it for good.
How to tell it’s a redirect hack
- Visitors are sent to a different domain, but the redirect often fires only on mobile, only from Google, or only for logged-out users — so it looks fine when you check while logged in.
- Google Search Console warns about redirects to a domain you don’t own.
- New admin users, unknown plugins, or a recently modified
.htaccessappear. - Ad networks or your host flag the site for malicious redirects.
If you’re not even sure the site is infected yet, start with our guide on how to scan WordPress for malware for free, then come back here to hunt the redirect.
Where the redirect is usually injected
The malicious redirect lives in one (or several) of these places:
.htaccess— rewrite rules that bounce visitors to the attacker’s domain.- Theme files — injected PHP in
functions.php,header.phporfooter.php. - Core files — a tampered file in
wp-admin/orwp-includes/, or a fake file that imitates a core one. - The database — a changed
siteurl/homeoption, or malicious JavaScript injected into posts and widgets. - A rogue plugin or mu-plugin — dropped to re-add the redirect after you clean it.
How to find the redirect (step by step)
1. Verify core files and spot unknown files
Run an integrity check that compares every core file against the official WordPress.org checksums. It instantly flags modified core files and files that don’t belong in wp-admin/, wp-includes/ or the site root — a very common place for redirect loaders to hide.
2. Scan every PHP file for injected code
A heuristic malware scan reads each PHP file in your plugins, themes and uploads and flags the patterns used by redirect injectors: obfuscated code, request-driven eval(), conditional redirects based on user-agent or referrer, and base64 blobs. It points you to the exact file and line.
3. Compare against a clean baseline
If you have a file baseline, compare it now: the redirect’s files will show up as added or modified. If you don’t have one yet, take it right after cleaning, so a re-injection is obvious within hours.
Forvault Security (free on WordPress.org) does all three from your dashboard, read-only — it never edits or executes your files, so it’s safe to run on the live, infected site.
How to remove the redirect safely
- Back up the whole site first (files + database) to keep the evidence.
- Restore a clean
.htaccess(WordPress can regenerate the default rules) and remove any unfamiliar rewrite block. - Reinstall WordPress core from the official source to overwrite tampered core files.
- Remove injected code from theme files, and delete any rogue plugin or mu-plugin the scan flagged.
- In the database, confirm
siteurlandhomepoint to your domain, and clear injected scripts from posts and widgets. - Rotate all passwords and secret keys, delete unknown admin users, then re-scan and take a fresh baseline.
Why the redirect keeps coming back
If the redirect returns a day later, the cleanup missed a piece of persistence — a hidden backdoor, a scheduled task, or a rogue admin that re-injects it. This is why monitoring matters: the Premium add-on adds scheduled scans, critical-file watching (including .htaccess), new-admin alerts and one-click quarantine, so a re-injection is caught and contained immediately. If you’d rather have it removed for you, our team offers a done-for-you cleanup.
How to prevent redirect hacks
- Keep core, plugins and themes updated, and delete anything you don’t use.
- Block PHP execution in
wp-content/uploads/and protect.htaccess. - Use strong, unique admin passwords and two-factor authentication.
- Keep a clean file baseline and re-check it regularly.
Frequently asked questions
Why does the redirect only happen on mobile or from Google?
Redirect malware often checks the visitor’s user-agent and referrer, firing only for mobile users or visitors arriving from search engines. That’s how it stays hidden from the site owner, who usually visits directly on desktop.
Can I fix a redirect hack without a plugin?
Yes, manually — but it’s slow to find every injection point. A scanner that checks core integrity and flags injected code makes locating it far faster.
Is Forvault Security free?
Yes. The malware scan, core integrity check and file baseline are all free on WordPress.org, with no trial limits.