Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Conditional redirect hack for search and ad visitors: fix it

OPS-141High impactPartlyBy FunnelGuardPublished Updated
On this page

What this issue is

A conditional redirect hack is code added to your site by an attacker. It checks where the visitor came from, using the HTTP Referer header or document.referrer. If the visitor came from a search engine or an ad platform, the code sends them to a spam, scam or malware page. If you open the site directly, nothing happens.

What an ad visitor experiences
  1. Ad or search clickVisitor arrives with a referrer
  2. Hidden redirectInjected code sees the referrer and fires
  3. Landing pageNever shown
  4. Form or checkoutNever reached
  5. ConversionNever recorded

The break happens only when a referrer is present, so direct checks miss it.

Why it costs you leads or sales

Every paid click that lands on a spam page is money spent for nothing. Organic visitors are lost the same way. Because you see nothing wrong, the problem can run for weeks while conversions fall and ad costs stay the same.

There is a second cost. Search engines and browsers can notice the behaviour and flag the site, which can bring warnings, ad disapprovals and ranking loss on top of the lost traffic.

Ad visitors who reach your landing pageExample numbers
Ad visitors who reach your landing page (example)Direct visits (what you see): 100 %; Ad clicks before the hack: 100 %; Ad clicks during the hack: 30 %0387710010030Direct visits (what y…Ad clicks before the …Ad clicks during the …%

Example: of 100 ad clicks, a referrer-only redirect sends most away while direct visits look healthy.

How to check if your site has it

You need to visit the site the way a customer does: arriving from a search result or an ad, in a clean browser with no logged-in admin session.

Reproduce the redirect
  1. Use a clean browser profile

    Open a private window, log out of your CMS and disable extensions. Admin sessions are often excluded from the hack.

  2. Arrive from Google

    Search for your brand or a page title, then click your result. Try on both mobile and desktop, because some hacks target mobile only.

  3. Arrive from your ad

    Open your own ad preview or tracked URL. Do not click your live ads repeatedly, as that wastes budget and may break ad platform rules.

  4. Test with a fake referrer in the terminal

    Run the curl command below and compare the response with a request that has no referrer.

  5. Check Search Console

    Open Security and manual actions, and use URL Inspection with Test live URL to see what Googlebot receives.

Compare responses with and without a referrerbash
# Normal request
curl -sI https://example.com/ | head -n 10

# Pretend to come from Google
curl -sI -e "https://www.google.com/" -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" https://example.com/ | head -n 10

# Look for a Location header or 301/302 status in the second result only

How to fix it

Removing the visible redirect is not enough. The attacker usually left a way back in. Work through cleanup and access in this order.

Clean up and lock down
  1. Take a backup and put the site in maintenance mode

    Keep a copy of the infected state for investigation, and pause ad campaigns pointing at the site while you work.

  2. Search for referrer checks

    Look for HTTP_REFERER, document.referrer, google, bing, gclid, base64_decode, eval( and unfamiliar atob( calls in files and in the database.

  3. Remove the malicious code

    Delete injected lines, not just the whole file, unless it is a file that should not exist. Replace core, theme and plugin files with fresh copies from the official source.

  4. Remove rogue users, plugins and scheduled tasks

    Delete unknown admin users, unused plugins and unfamiliar cron jobs, which are common ways for the hack to return.

  5. Change every credential

    Reset passwords for the CMS, hosting, FTP/SFTP, database, email and tag manager. Rotate API keys and invalidate all sessions.

  6. Update everything

    Update the CMS, themes and plugins. Remove anything abandoned or pirated.

  7. Request a review if flagged

    If Search Console or Google Ads reported an issue, submit a review request after cleanup.

Where to look on your platform
  1. Check .htaccess

    Open .htaccess in the site root and look for RewriteCond %{HTTP_REFERER} lines. Restore the default WordPress rules.

  2. Check theme and plugin files

    Inspect header.php, footer.php, functions.php and the wp-content/mu-plugins folder. Reinstall themes and plugins from fresh copies.

  3. Check the database

    Search the wp_options and wp_posts tables for <script tags you did not add, including the header and footer fields of any script-insertion plugin.

Find suspicious code on a server you controlbash
grep -RniE "HTTP_REFERER|document\.referrer" --include=*.php --include=*.js --include=.htaccess /var/www/html | head -n 50

# Files changed in the last 14 days
find /var/www/html -type f -mtime -14 -not -path "*/cache/*" | head -n 100

How to confirm it's fixed

Confirmation checks
  • Click through from a Google result on mobile and desktop and reach the correct page
  • Open a tracked ad URL and reach the correct landing page
  • The curl test with a Google referrer returns the same response as without one
  • A search for your code patterns returns only legitimate matches
  • Search Console shows no security issues, and URL Inspection live test shows the real page
  • A test form submission or checkout step still works end to end
  • No unknown admin users, plugins or tag manager users remain

How to prevent it happening again

Prevention
  • Keep the CMS, themes and plugins updated and delete unused ones
  • Use unique strong passwords and two-factor authentication on hosting, CMS and tag manager
  • Limit admin accounts and review them monthly
  • Turn off file editing in the CMS dashboard where possible
  • Keep off-site backups so you can restore a clean version
  • Review third-party scripts and tag manager changes regularly
  • Test your landing pages from a search and ad arrival after every major change

How FunnelGuard handles this

FunnelGuard detects this only partly. It runs your real journeys with a robot visitor on a schedule, and a synthetic ad arrival can catch a redirect that fires for ad traffic: if the robot lands somewhere other than your page, the step fails and you get one alert with a screenshot and a likely cause, after a re-check from a second region.

Visitor from an ad is sent elsewhere

The injected code reacts to the referrer and diverts the visitor before the page loads.

Questions people ask

Why does my website redirect only when I come from Google?

Most likely malicious code checks the referrer and redirects only visitors who arrive from search engines or ads. It hides the redirect from you and from direct visits. Search .htaccess, theme files, the database and your tag manager for referrer checks and unknown redirects.

Why is my site fine when I type the URL but redirects from ads?

A hack can be set to fire only when a referrer or ad parameter such as gclid is present. Typing the address sends no referrer, so the code stays dormant. Test with a clean private window, arriving from a search result or an ad preview.

How do I test my site for a referrer-based redirect?

Open a private window, log out of your CMS, and click through from a Google result on mobile and desktop. You can also run curl -sI -e https://www.google.com/ https://yoursite.com/ and look for a Location header or 301/302 status that does not appear without the referrer.

How do I remove a conditional redirect hack from WordPress?

Restore the default .htaccess, reinstall the theme, plugins and core from clean copies, and search the database for unknown script tags. Then delete rogue admin users and change all passwords. Without the credential reset, the hack often returns.

Can Google penalise my site for a redirect that only affects some visitors?

Yes. Sneaky redirects that send users somewhere different from what search engines see can bring security warnings, manual actions or ranking loss. Check Search Console's Security and manual actions reports and request a review after cleanup.

Can FunnelGuard detect a redirect that only happens for ad traffic?

Partly. Its synthetic ad arrival can catch a redirect that fires on ad-style visits, and it alerts you with a screenshot. It does not scan your files for malware and may miss hacks aimed at specific countries, devices or real search clicks, so keep checking by hand too.

Why did my ad conversions drop but my site looks fine?

If the site only misbehaves for visitors arriving from ads, your own visits will look normal while paid visitors are redirected. Compare ad clicks with landing page sessions and test a real ad arrival from a clean browser.

Does FunnelGuard catch this?

Partly

FunnelGuard checks part of this.

How: Synthetic ad arrival may catch it.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.