Troubleshooting guide · website-errors · Published 2026-08-16 · 4 min read

Website redirection to spam or scam pages

Stop a website redirecting to spam or scam pages: find the injected redirect, check providers and plugins, and clean the payload.

When a visitor types your domain and lands on a pharmacy page, a casino, or a fake download, the redirect is not a WordPress setting. It is injected code. The site owner usually does not see it because the redirect only fires for certain visitors: a specific referrer, a search-engine bot, a device, or an X-Forwarded-For ward. That selectivity is part of the code, and it tells you how to find the payload.

Map the layers that can redirect

A visit can jump at four levels, and the fix differs per layer:

LayerWhat firesSignal
Web server.htaccess RewriteRule, nginx returnRedirect fires for www and bare domains alike, even the homepage
Scriptindex.php include, wp-config requireRedirect fires when the CMS loads
Front endInjected <script> in a pageVisitor sees it only after the page starts
DNS/edgeA hijacked DNS record, or provider pageThe whole domain flips at once

Trace which layer fires

  1. Use curl to bypass the browser. The browser marks some scripts (like a document.location writer) invisible to a live probe. Test with the headers a search engine sends:
curl -I -A "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" https://example.com/

Compare the same fetch with a plain user agent and from a different network. If the redirect only appears for the bot agent, or only for one referrer, you have a script payload that reads values.

  1. Open the page source. The injected script sits before your content in the HTML, or a meta refresh in the head. Search for location.href, window.location, document.write, or a setTimeout writer.
  2. Check the raw response body. A DNS- or panels-level redirect returns a 301/302 header with the spam host, while a payload inside the page returns a 200 with the script inside.

Check the quiet keepers

Stop the redirect

  1. Cut the network first. The page redirects every visitor while it lives, so keep the site behind a maintenance notice or a redirect yourself, offline, while you clean.
  2. Remove the payload file or row and the sink that reads it. Delete the .htaccess block if that is the layer; in nginx, restore the www and location directives from backup.
  3. Scan and clean per the malware removal checklist: reset, reinstall core, reset admin access.
  4. Verify with curl for the bot agent and a normal browser in a private window; a redirect that fights the cloudflare or cache layer is the same payload cached, so purge the edge after the files are clean.

Why it came back

The redirect returns within days because the hole is still open: an unpatched plugin, an exposed wp-cron, or a compromised install directory. If the payload came back to the same file, the entry vector is the door; an exchange of the file only closes the symptom. Track the source IP and probe page in the access log, then fix the underlying weakness (outdated plugin or a leaked credential) before you call it clean.

When to involve a professional

If the redirect follows you across a clean reinstall, or the traffic is being farmed, hand it to a professional response team. They will isolate, clean, and verify the platform's logs, and they can advise a block-list watch while you rebuild.

Need a website built, fixed, optimised, migrated or replaced?

This technical resource is written by CSMBAC, a small design and development studio. If you would rather hand the problem to a professional, the website service page explains how we build enquiry-ready websites.

Explore website services