Website Malwareintermediatethreat profile

Malicious Redirects

Conditional redirects send your mobile or search visitors to scam pages while the site looks normal to you. How they are implemented and how to trace them.

Cyber Security Space editorial desk · Published 25 Jun 2026 · Updated 22 Aug 2026 · 2 min read · Reviewed 22 Aug 2026

Short answer

A malicious redirect is injected code on a compromised website that sends visitors to an attacker-controlled destination, usually only under specific conditions such as arriving from search results, using a mobile device, or visiting for the first time, which is why the site appears normal to its owner.

Key takeaways

  • Redirects are conditional by design: reproduce them with a mobile user agent, a search referrer and no cookies before concluding the site is clean.
  • Injection points fall into four buckets: server config, PHP includes, database content, and third-party JavaScript.
  • A redirect chain often passes through several hops; capture the full chain rather than just the final URL.
  • Redirects delivered by a compromised third-party script are fixed at the script provider, not in your own files.

Where do malicious redirects live?

LocationTypical formHow to check
Server configuration.htaccess or nginx rules keyed on user agent or referrerReview config files and compare against version control
Application codeA header() call in an include loaded on every requestDiff core, theme and plugin files against official releases
Database contentInjected script tags in post content or site optionsSearch stored content for script tags and unfamiliar domains
Third-party scriptA compromised or hijacked analytics, ad or widget scriptWatch the network waterfall for the first request to the redirect domain

How do you reproduce a redirect you cannot see?

  1. STEP 01

    Use a clean session

    Open a private window, or clear cookies. Many redirect payloads fire once per visitor and then set a suppression cookie.

  2. STEP 02

    Emulate a mobile device

    Switch to a mobile user agent in devtools. Mobile-only redirects are the most common variant.

  3. STEP 03

    Arrive from search

    Set a search engine referrer, or click through from a search result, since many payloads check the referrer.

  4. STEP 04

    Capture the full chain

    Record every hop with response codes and the initiator of each request. The initiator tells you which file or script triggered it.

curl -sIL -A "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X)" \
  -e "https://www.google.com/" https://example.com/ | grep -Ei "^(HTTP|location)"

How do you remove a malicious redirect?

  1. Identify the initiator from the captured chain before editing files.
  2. Restore the affected config or code file from a known-good copy.
  3. Clean injected script tags from the database, including cached fragments.
  4. Remove or pin third-party scripts you do not control; add Subresource Integrity where the provider supports it.
  5. Purge caches and CDN, then re-test with the same mobile and referrer conditions.
  6. Rotate credentials and check for backdoors and scheduled tasks.

What damage do malicious redirects cause?

The visible cost is lost traffic and conversions. The larger costs are a browser-level Deceptive Site warning, removal from search listings, and the reputational damage of customers landing on scam pages carrying your brand. Because the redirect is conditional, this can continue for weeks before anyone internally reproduces it.

Frequently asked questions

Why does the redirect only happen on mobile?
The payload inspects the user agent and fires only for mobile devices, because mobile users are less likely to inspect the URL bar and site owners usually test on desktop.
The redirect stopped after one visit. Is it gone?
Probably not. Most payloads set a cookie so each visitor is redirected once. Test again in a private window with cookies cleared.
Can a redirect come from an ad or analytics script?
Yes. If the first request to the redirect domain is initiated by a third-party script, your own files are clean and the fix is to remove or replace that script and notify its provider.

Sources

Read next

  • SEO Spam

    Cloaking

    Cloaking serves different content to search engines than to people. It is the mechanism that keeps most injected spam invisible to site owners.

  • Website Security

    How to Check if a Website Is Hacked

    Eight checks that reliably separate a compromised site from a slow or misconfigured one, in the order that finds problems fastest.

  • Website Security

    SEO Spam: The Complete Picture

    The pillar page for injected search spam: the attack family, how the variants relate, and the detection and remediation path shared by all of them.