If you visit your own website and suddenly land on a pharmacy, casino, or scam page, you have a spam redirect hack. It is one of the most common and most damaging WordPress infections, because it hijacks the visitors and the search reputation you worked to build. Here is exactly why it happens and how to fix it.

A redirect hack is malicious code added to your site that sends visitors somewhere you did not intend. The redirect is often conditional: it may only trigger for visitors arriving from Google, only on mobile, or only for people who are not logged in. That is why a site can look fine to you while sending every real visitor to spam.
Attackers exploit a weak point, almost always an outdated plugin or theme or a weak admin password, then inject code into one or more places:
functions.php or header.phpwp-config.php or index.php.htaccess filewp_options or wp_postsBecause the code can hide in several spots at once, removing it from one file is rarely enough.
Test in a private or incognito window, and click through from a Google search result rather than typing the address. Check on both desktop and mobile. If the redirect appears for visitors but not when you are logged in, that is a strong sign of a conditional redirect. A malware scan of files and database will confirm it.
A reliable cleanup follows the same steps every time:
wp_options and wp_postsIf any of that is beyond what you want to take on, our Hacked Site Repair does the whole process for a flat fee, with a full refund if we cannot clean it.
Redirect hacks return when the entry point is left open. Keep everything updated, enforce strong passwords and two-factor login, remove unused plugins, and run monitoring. An ongoing care plan handles all of this so a one-time cleanup stays clean. For the bigger picture, see our WordPress security guide.
Redirect hacks rarely live in just one file, which is why a surface cleanup almost always fails. The same hack will quietly reinfect through whatever spot you missed. These are the places we check first, in roughly this order:
wp-config.php. Attackers append a small PHP snippet near the top so it runs on every page load. It is often obfuscated with base64 or hex encoding.functions.php in the active theme. Easy to edit, runs on every request, and easy to hide inside a long file. Always check the child theme if you have one..htaccess at the document root and inside wp-content/uploads. Used to redirect specific paths, block search-engine bots, or send mobile users only to spam.index.php in WordPress core. Sometimes overwritten entirely with a malicious version. A diff against a fresh WordPress download flags this fast.wp_options (often siteurl, home, or custom option names) and wp_posts rows containing injected JavaScript.wp-content/plugins/ with innocuous names like wp-cache.php or social.php that never appeared in the plugins admin.Checking just one or two of these spots is the most common reason the redirect returns within hours. A real cleanup covers all of them, then closes the entry point that let the attacker in.
Not every weird redirect is a hack. Before you start tearing into your site, rule out the simpler causes, because the fix is very different:
If those are all clean and the redirect persists, especially when arriving from Google or on mobile, you are almost certainly looking at a real WordPress infection and the cleanup steps above apply.
A spam redirect rarely shows up alone. By the time visitors are being sent to pharmacy or casino sites, the attacker has usually planted several other things you may notice:
If you see two or more of these alongside the redirect, treat it as a confirmed hack and start the cleanup, or bring in a professional. We cover the full diagnostic in 7 signs your WordPress site is hacked.
$199 within 2 business days, or $299 the same day. Full refund if we cannot clean it.
Start a repair →Attackers make the redirect conditional so it is harder for the owner to notice. It can target visitors from search engines, mobile devices, or logged-out users specifically.
Yes. It sends them to scam and malware pages and destroys their trust in your brand. Google may also blacklist the site to protect users.
If you are comfortable editing core files and the database and finding every injection point, yes. Most owners prefer a professional cleanup because missing one hidden file lets the hack return.
Most redirect infections are cleaned within 2 business days, or the same day with priority service.
Free site check, plain report, no sales call.
or email contact@backstopweb.com