On this page
What this issue is
A malicious redirect is code an attacker has planted on your site or server. It checks who is visiting and, for certain visitors, sends them to another address. Typical targets are mobile devices, visitors with a gclid or other ad parameter in the URL, or people who come from Google or social networks.
The hack hides from the owner on purpose. If you open the site on your laptop by typing the address, it loads normally. The redirect only fires for the visitors who are most valuable to you.
Common hiding places: .htaccess or nginx rules, JavaScript added to theme files or the database, tampered plugins, tags in your tag manager, and index.php or wp-config.php edits.
Why it costs you leads or sales
Every redirected visitor is a lost lead, and if they came from a paid ad you still pay for the click. Because the hack targets mobile and ad traffic, your conversion rate drops while analytics may show only a small change in total traffic. Search engines and browsers may also flag the site, which hurts trust and rankings.
- Ad clickVisitor on a phone clicks your ad
- Landing URLInjected code detects mobile and ad parameter
- Spam pageVisitor is sent to a scam or unrelated site
- Form or checkoutNever reached
The redirect fires before the page content or form loads.
Example: desktop converts as usual while mobile ad traffic collapses after the hack.
How to check if your site has it
Open your landing page on a real phone
Use mobile data, not your office Wi-Fi, in a private tab. Add a fake ad parameter such as ?gclid=test123&utm_source=google.
Emulate mobile on desktop
In Chrome DevTools, toggle the device toolbar and pick a phone. Open the Network tab, tick Preserve log, and reload to see which request returns a 301 or 302 and where it points.
Test with a referrer
Search for your brand on Google on a phone and click your result. Some hacks only trigger when the referrer is a search engine.
Check the response from the command line
Run the curl command below and look for Location headers.
Ask customers and your ad team
Reports of 'your site took me to a casino' or a sudden drop in mobile conversions are strong signals.
curl -I -L -A "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1" -e "https://www.google.com/" "https://example.com/landing?gclid=test123"How to fix it
Find the redirect source
Search server config and files for rules or scripts that redirect by user agent, referrer or query string. Look for
RewriteCond %{HTTP_USER_AGENT},HTTP_REFERER,window.location,eval(,atob(andbase64_decode.Restore clean files
Replace core files, themes and plugins with fresh copies from the official source or your last known clean backup. Delete plugins and themes you do not use.
Clean the database
Check posts, widgets, theme options and custom code fields for injected script tags.
Remove unknown users and backdoors
Delete admin accounts you do not recognise and look for recently modified or oddly named PHP files, especially in uploads folders. Attackers often leave a way back in.
Rotate every credential
Change hosting, FTP/SFTP, database, CMS admin, and API keys. Regenerate the secret keys and salts in
wp-config.phpif you use WordPress.Patch the entry point
Update the CMS, themes and plugins, and remove the vulnerable component that let the attacker in.
Reinstall core
Go to Dashboard > Updates > Re-install version, or replace wp-admin and wp-includes by hand. Check the root .htaccess, wp-config.php and the active theme's header.php and functions.php.
Review users and plugins
Under Users, remove unknown administrators. Under Plugins, delete anything unfamiliar or abandoned and reinstall the rest from wordpress.org.
Inspect theme code
In Online Store > Themes > Edit code, check theme.liquid and any snippets for unknown script tags. Compare against a fresh copy of your theme.
Audit apps and staff
Remove apps you do not recognise, check Settings > Users and permissions, and look at Settings > Customer events for unknown pixels.
Review tags and users
Look for Custom HTML tags you did not create, especially ones with redirect or obfuscated code. Check Admin > User management and remove unknown users, then publish a clean version.
Check custom code
Review Site settings > Custom code and each page's custom code for unknown scripts. Remove unknown collaborators and rotate your account password.
Check funnel and site code
Open each funnel or website's Settings > Tracking code and custom code areas for unknown scripts, and remove unknown team members.
Check custom code and collaborators
In Settings > Custom code, remove scripts you did not add. Review contributors and change your password.
Check code injection
Under Settings > Advanced > Code injection, remove unknown scripts. Review contributors under Settings > Permissions.
Check server rules
Review .htaccess, nginx config, index files and any included JavaScript. Compare with version control or a clean deploy and redeploy from a trusted source.
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (android|iphone|mobile) [NC]
RewriteCond %{QUERY_STRING} gclid [NC]
RewriteRule ^(.*)$ http://spam.example/landing [R=302,L]Hacked
- Desktop looks normal
- Phone with gclid is redirected
- Ad spend wasted
Cleaned
- Same page on every device
- Ad parameters kept
- Form and checkout reachable
How to confirm it's fixed
- Phone on mobile data loads the landing page with ?gclid=test123
- curl with a mobile user agent and Google referrer returns 200 with no unexpected Location header
- Search results click-through on a phone lands on your page
- Submit a test lead and confirm it reaches your inbox and CRM
- No unknown admin users, plugins or scripts remain
- Google Search Console shows no security issues
How to prevent it happening again
- Keep CMS, themes and plugins updated and delete unused ones
- Use unique strong passwords and two-factor authentication for hosting, CMS and tag manager
- Limit admin accounts and review them monthly
- Keep off-site backups you can restore quickly
- Use a web application firewall or host-level malware scanning
- Turn on file change alerts
- Test your key landing pages on mobile with ad parameters after every deploy
How FunnelGuard handles this
FunnelGuard detects this only partly. It runs a redirects check on your journey URLs: when the robot visitor loads a step and ends up somewhere unexpected, the run fails, a second region re-checks it, and you get one alert with a screenshot and a likely cause.
What it does not do: it is not a malware scanner, it does not inspect your server files, database or users, and it cannot see redirects that only fire for conditions the robot does not match, such as a specific real phone, a real ad click or a particular referrer. It never clicks real ads.
Cover the rest by hand: run the phone and curl tests above after changes and on a regular schedule, watch mobile conversion rate by device in your analytics, check Search Console's Security issues report, and use a server-side malware scanner and file integrity alerts.
Questions people ask
Why does my website redirect to spam only on mobile?
Malicious code often checks the visitor's user agent and redirects phones only, so site owners testing on desktop see nothing wrong. Look for redirect rules in .htaccess or server config, injected JavaScript in theme files or the database, and unknown tags in your tag manager.
Why are my Google Ads visitors being sent to another site?
Some hacks trigger only when the URL contains an ad parameter like gclid or when the referrer is Google. Test your landing page with ?gclid=test123 on a phone and check the Network tab for 301 or 302 redirects.
How do I find a redirect hack in my website files?
Search for rewrite rules using HTTP_USER_AGENT or HTTP_REFERER, and for JavaScript using window.location, eval, atob or base64_decode. Also check recently modified files, theme header files, wp-config.php and database content.
Is a redirect hack the same as a Google Safe Browsing warning?
No. A redirect hack is the infection itself, while a Safe Browsing warning is a possible consequence once Google detects it. You can have the redirect for weeks before any warning appears.
How do I stop my site being hacked again after cleaning it?
Close the entry point by updating or removing vulnerable plugins and themes, rotate all passwords and keys, remove rogue admin users and backdoor files, and enable two-factor authentication. Keep off-site backups and run regular scans.
Can FunnelGuard detect a malware redirect?
Partly. It runs a redirects check on your journey URLs and alerts you if a step ends up somewhere unexpected. It is not a malware scanner and cannot catch redirects that only trigger for real phones, real ad clicks or specific referrers.
Will cleaning the site stop ad money being wasted?
Once visitors reach your page again, yes. Confirm with a phone test using an ad parameter, then check that ads point to working URLs and that mobile conversions recover in your analytics.
Related issues
- OPS-141Conditional redirect hack only for search/ad referrersFix guide
- OPS-138Google Safe Browsing 'Deceptive site' warningFix guide
- OPS-139Chrome 'dangerous site' red screen on funnelFix guide
- OPS-147Injected popups / malvertisingFix guide
- OPS-149Backdoor files (web shells) on serverFix guide
- OPS-154SEO spam in title/meta for Google only (cloaking)Fix guide