When it only happens on phones or from Google

Website redirecting to another site? How to find the cause and fix it

Visitors open your website and land on a spam, scam, adult or gambling site instead. Yet when you check on your own computer, everything looks normal. Here is how to tell what is causing it, how to reproduce the redirect, where the redirect code usually hides, and how to get rid of it.

No sign-up needed. We only look at public information anyone can see, the same way an ordinary visitor would.

The short answer: why your site redirects, and what to do first

  • If the redirect only happens on mobile, or only when people click your site in Google, your site has very likely been hacked. Attackers often redirect only visitors who match certain conditions, so the owner never sees it.
  • Seeing a normal site on your own computer proves nothing. The quickest test is to turn off Wi-Fi on a phone, search for your business on Google, and tap your result.
  • The redirect code usually sits in one of four places: the .htaccess file, JavaScript added to your theme, the WordPress site address settings, or a plugin you never installed.
  • Deleting the redirect is not enough. If you do not close the way in (usually an outdated plugin or a weak password), it tends to come back within days.
  • If you confirm a hack, do the first-hour steps first: record what you see, take the site offline, change passwords and call your hosting company.

Website redirecting to another site: is it really your site?

A redirect can come from a hacked site, but also from a bad ad or from the visitor's own device. Who gets redirected, and when, usually tells you which.

What happensLikely cause
Only on phones, only from search results, or only on the first visitYour site has been hacked with a conditional redirect. This is the most common case.
Everyone, on every page, including the admin loginThe WordPress site address has been changed, or your domain's DNS settings have been changed.
Only on certain pages, when an ad loads or is clickedA malicious ad from an ad network. Your site's own files may be clean.
Only on one person's device, on many different websitesA problem on that device: a browser extension, allowed notifications or a dodgy app.

If the problem is on the visitor's device, your site does not need fixing. But if customers tell you they were redirected, it is safer to assume the site is the problem until you have checked.

Why the site redirects on mobile only, but not for you

Google's spam policies describe exactly this: hackers inject code that redirects some users to harmful or spammy pages, and the redirect can depend on the referrer (where the visitor came from), the user agent (which browser) or the device. A link in Google Search may redirect, while typing the same address directly does not.

Attackers want the redirect to survive as long as possible, so the code often skips anyone likely to be the owner:

  • people logged in to WordPress (you and your web developer)
  • people who type the address or use a bookmark
  • desktop visitors (only phones are targeted)
  • repeat visits from the same office connection
  • anyone already redirected once (some code sets a cookie and waits before doing it again)

While you wait for it to happen to you, every customer arriving from search is being sent somewhere else. If Google flags the site, a warning may also appear next to your search results.

How to check if your site redirects (phone, Google, curl)

Start at the top. The first three checks need no login.

  1. 1

    Use a phone on mobile data, coming from Google

    Turn off Wi-Fi so you are not on your office network. Open a private window, search Google for your business name, and tap your own result. Try two or three other pages from your search results too, not just the home page.

  2. 2

    Search Google for site:yourdomain.com

    Look for pages you never created: product names, pharmacy terms, foreign-language titles. Redirect hacks often come with thousands of spam pages on your domain.

  3. 3

    Check what Google sees in Search Console

    If your site is in Google Search Console, open Security issues. Then paste a page address into the URL Inspection bar, click Test live URL and view the tested page. Content or links that do not appear on your screen are a strong clue.

  4. 4

    Ask your developer to fetch the page as a phone

    Someone comfortable with the command line can use curl with -A (to pretend to be an iPhone or Android browser) and -e (to pretend to come from Google), and see whether the server answers with a 301 or 302 redirect or a script that changes the page location. Ask them to "check whether the site redirects for mobile visitors from Google."

If none of these trigger the redirect, that is not proof your site is clean. Some code only fires at certain times or for a share of visitors. If customers keep reporting it, have your host or a cleanup specialist look at the files.

Where a WordPress redirect hack usually hides

The redirect is usually in one or more of these places. Attackers often plant it in several spots so it returns if you only remove one.

The .htaccess file

A server settings file in your site's main folder. Look for RewriteCond lines mentioning google, iPhone or Android, followed by a RewriteRule pointing at a domain you do not know. Google's own guide to the cloaked keywords hack names .htaccess as the file this kind of attack uses.

JavaScript added to the theme or content

A script line loading an unfamiliar domain, added to the top or bottom of header.php, footer.php or functions.php, to a widget or inside posts. It is often scrambled into long strings of meaningless characters.

The WordPress site address

Under Settings, General, the WordPress Address and Site Address are changed to another domain. Then everyone is redirected on every page, including the admin login. The values are stored as siteurl and home in the wp_options database table.

A plugin you never installed

An unknown plugin, or one named to look like a real one. Some hide themselves from the plugin list or sit in wp-content/mu-plugins, a folder whose plugins run automatically.

Sites not built on WordPress are hit the same way: the .htaccess file and the header or footer shared by every page are the usual targets.

How to fix a WordPress redirect hack

Before fixing anything, do the first-hour steps: record evidence and change passwords from a clean device. Then work through this with your host or developer.

  1. 1

    Take a full copy first

    Copy the files and the database as they are now. The hacked state shows how the attacker got in.

  2. 2

    Restore a clean backup if you have one

    Restoring from a date before the redirects started is the most reliable fix. If you do not know when it started, pick an older backup.

  3. 3

    Otherwise, check the four hiding places

    Look through .htaccess, the theme files, the site address settings and the plugin list. If the address was changed and you cannot reach the admin, WordPress's official documentation explains how to set WP_HOME and WP_SITEURL in wp-config.php or correct siteurl and home in the database.

  4. 4

    Reinstall WordPress, themes and plugins from official sources

    Replace core, theme and plugin files with fresh copies from the official sources. Delete plugins and themes you do not use.

  5. 5

    Close the way in

    Remove admin rights from unknown users, change every password and turn on two-factor authentication. Check old plugins against the WordPress plugin vulnerability list.

  6. 6

    Test again from a phone and from Google

    Repeat the checks above, then again a few days later to make sure it has not returned. If Google showed a warning, request a review in Search Console.

If you are not used to editing server files, a hosting company or cleanup specialist will be faster and more thorough. A single missed file brings the redirect back.

Preventing it again: what Security Ready can and cannot do

Most redirect hacks get in through an outdated plugin or theme or a weak password. Our guide on checking WordPress for vulnerabilities covers what to look at.

First, the limits. Security Ready does not clean up hacked sites or remove malware. An external scan also cannot prove that no redirect code exists.

What it does is find the weak spots attackers use to get in. Automated external scans check for known vulnerabilities in outdated software (around 14,000 checks), exposed files that should not be public, forgotten subdomains and more, and send you how to fix each one. The Standard plan's internal check also reports your WordPress plugin and theme versions and their known vulnerabilities.

For a quick look at what is visible from outside, the free 30-second check covers your certificate, https, email spoofing protection and forgotten subdomains. It does not detect redirects or malware. Use it to check the doors once the site is clean.

Frequently asked questions

Why does my site redirect on mobile only?

Most likely a hack that targets phones only, because owners usually check their site on a computer. Test from a phone on mobile data, opening your site from a Google search result.

My site only redirects when people click it in Google. Is it hacked?

Very likely. Code that checks whether a visitor came from Google is a known hacking technique described in Google's own spam policies. Check .htaccess and your theme files, and follow the hacked website steps.

I can't reproduce the redirect myself. Am I imagining it?

Not necessarily. Many redirects skip logged-in users, visitors who were already redirected once and repeat visits from the same connection. Ask someone else to try on their phone, on mobile data, from a Google result.

Even my WordPress admin redirects to another site. What happened?

The site address settings (siteurl and home in the database) have probably been changed. You can set the correct address in wp-config.php or fix the values in the database. If that sounds unfamiliar, tell your host the site address was changed and ask for help.

I removed the redirect but it came back a few days later. Why?

Either the code was in more than one place, or the way in is still open: an outdated plugin, a weak password or a hidden backdoor file. Reinstall core and plugins, change all passwords and check for unknown admin users, all in one go.

Can Security Ready find and remove the redirect for me?

No. We do not clean up hacked sites or remove malware. Security Ready finds the weak spots attackers use to get in and tells you how to fix them. Have your host or a cleanup specialist remove the redirect, then use the scan to keep the doors shut.

See where your own site stands — free

The free in-depth scan checks your site from the outside against thousands of known weaknesses and tells you how to fix each one. No payment details needed. For businesses; scans only with the owner's authorization.