My website has been hacked and redirected: how casino redirect hacks work, and how they are cleaned up

Visitors from Google land on a casino or pharmacy site, but the page looks fine when you open it. Here is what the hacker has done, why you can't see it, where the code hides and what a proper clean-up involves.

“My website has been hacked and redirected” usually means someone has added code to your site that sends some visitors, often those from Google or on phones, to a casino, pharmacy or other spam site, while the same page looks normal to you. It is an SEO-spam hack: the hacker is borrowing your site’s standing in Google to earn money from its traffic. Here is how it works, why you may not see it, where the code hides and how a clean-up is done. The first-day steps for any hack are in what to do if your website is hacked.

How a redirect hack works, and why hackers do it

Google’s spam policies list redirects among the forms of hacked content: hackers might inject malicious code that redirects some users to harmful or spammy pages, and the kind of redirect sometimes depends on the referrer, user agent or device.

Its example: clicking a URL in Google Search results could redirect you to a suspicious page, with no redirect when you visit the same URL directly. The redirect is usually one half of the hack; the other half is content. Google’s spam policies describe page injection (new spammy pages) and content injection (hidden links or text in your existing pages, which search engines can see but which may be harder for you to spot). Google’s guide to the cloaked keywords and links hack says the hacked pages are created to manipulate Google’s ranking factors, that hackers often try to make money by selling the links on them, and that the pages often also redirect visitors to an unrelated page where hackers earn money. The casino site is not the point; your domain’s place in Google’s index is.

Why you may not see the redirect yourself

Because the hacker arranged it. The redirect runs only for certain visitors, typically those from Google or on phones, not for you opening the site directly. Google’s help page for the Security Issues report says hackers might hide the spammy content using cloaking techniques to avoid detection by site owners; Google’s spam policies define cloaking as presenting different content to users and search engines. Google’s Security Issues help page says hackers often attack only specific user agents or referrers.

Under sneaky redirects, the spam policies give the example of mobile users sent to a spam domain while desktop users see a normal page. Google’s help page for the Security Issues report adds that many hackers make changes visible only to Google’s machines, and Google’s guide to the cloaked keywords and links hack says a hacked page may even show you a 404 “not found” message so you think it is fixed.

What you seeWhat it usually meansHow to confirm it
A customer says your site sent them to a casino site; it looks fine to youA redirect that runs only for visitors from Google, or only on phonesAsk what they searched for and on which device; check Search Console’s Security Issues report
A page in Google’s results that you never wrote shows “not found” when you open itThe page may be cloaked: gone for you, live for GoogleInspect the address in Search Console’s URL Inspection tool
An email that someone you don’t know has verified your site in Search ConsoleA hacker has added themselves as an owner in Google’s toolsCheck the property’s users and owners in Search Console
Signs of a redirect hack, what each means, and how to confirm it

Google’s Security Issues help page says to use the URL Inspection tool, not a browser, to see a page as Google sees it; Google’s help page for the URL Inspection tool says a live test shows a screenshot and follows a redirect. Google’s guide to the Japanese keyword hack says that if someone you don’t know has verified your site in Search Console, there is a strong possibility it has been hacked.

Where the redirect code hides

In three kinds of place: the server’s configuration file, .htaccess; code inside your pages or the PHP files that generate them; and the injected pages themselves. Each is covered below.

WordPress.org’s guide for hacked sites says the one file you will definitely want to look at is .htaccess: it is one of the files most often used for nefarious activities, whatever the infection, usually at the root but sometimes in other directories too. Google’s Security Issues help page calls this a header redirect: the server sends the visitor elsewhere before your page loads.

Inside your pages, Google’s help page lists JavaScript redirects, scripts loaded from another site, and code scrambled to hide what it does, in your HTML or the PHP files that generate your pages. WordPress.org’s guide names the files to watch: index.php, header.php, footer.php and the theme’s functions file.

The injected pages are generated from template files and scripts the hacker leaves behind, Google’s guide to the gibberish hack says.

What a proper clean-up involves

A proper clean-up replaces the hacked files rather than repairing them, removes everything the hacker added, their own access included, closes the way in, and proves the spam pages are gone before Google is asked to look again. That is the order Google’s own guides to these hacks follow. As the owner, you need to know what to ask for, not how to do it; our paid clean-up and the rebuild option follow the list.

  • A copy of the site as it is, kept before anything is changed. Google’s cloaked keywords guide says to back up the entire site offline, database included, before starting.
  • Clean replacements, not repairs. The server’s configuration files are replaced with clean ones, and WordPress, the theme and every plugin are reinstalled from fresh copies, so those files are clear of hacked content; why a clean install, not an upgrade, after a hack is explained in the first-24-hours guide.
  • A search for what does not belong. With clean copies in place, Google’s cloaked keywords guide says to look only at the files that are not part of the defaults.
  • The hacker’s access removed. Google’s Japanese keyword hack guide says to revoke a Search Console owner you don’t recognise as soon as possible. Every password is then changed again, as WordPress.org’s guide says.
  • The way in closed. Google’s help page for the Security Issues report lists the usual ways in: a folder left with open permissions, an older, insecure version of WordPress, or a hacked third-party plugin. Have whoever cleans the site tell you which it was, in writing.
  • Proof, then a review. Google’s cloaked keywords guide says to check the hacked pages again with Google’s tool; if they now come back as not found, the guide says chances are you are in good shape. Google’s Security Issues help page says to request a security review there once the fix is confirmed; how to get Google’s warning removed covers what the review involves and how long it takes.

Our website rescue clean-up covers a response within 24 to 48 hours, malware removal, hardening (making the site harder to break into), Wordfence configured and, if Google has flagged the site, a request for Google to review it. It costs from R5,200 incl. VAT, followed by at least three months on a care plan, paid on top of the clean-up.

When the build is not worth saving, we rebuild it clean instead. Xscape4u’s site had the content half of this hack: links to offshore casino sites were being injected into it when the tourism and accommodation business was referred to us. The developers who had been helping could not fix the compromise, and Xscape4u chose to move to us. Rather than hunt for every injected file, we rebuilt the entire platform, extracted its data, left the hacked content out and delivered it clean, with encryption and Wordfence. The full story is in the Xscape4u case study. A rebuild starts at R15,000 incl. VAT, quoted after an assessment of R2,220 incl. VAT that is credited against the work.

What to ask before accepting that the site is clean

Ask four things, in writing: whether every server configuration file, in every folder, was replaced; whether the files were compared against fresh copies rather than only scanned; which users and Search Console owners were removed; and how the hacker got in and what closed it. A redirect hack comes back when one is missed. Then ask what happens next.

  • The four answers, in writing. A scan report is not an answer to any of them.
  • What happens afterwards. A clean site stays clean only if someone keeps it that way: on our care plans, from R975 a month incl. VAT with hosting included, the site is backed up before every update and Wordfence monitors it.

If your site is sending visitors to casino sites, our website rescue service cleans it up or rebuilds it clean. Get a quote: tell us what your customers are seeing, and we reply the same business day.

Frequently asked questions

Why is my website being redirected?

Because a hacker has added code that sends visitors elsewhere, usually to a site they earn from. Google’s spam policies say the redirect can depend on the referrer, browser or device, so visitors from Google or on phones are sent away while you see a normal page.

How do I unhack a website?

Copy the whole site as it is, then replace rather than repair: clean server configuration files, fresh copies of WordPress, the theme and every plugin, and every file that is not part of them removed. Remove unknown users and Search Console owners, change every password again, close the way in, then ask Google to review it.

What to do if my website gets hacked?

Have a copy of the site made as it is, before anything is changed, then have it cleaned by replacing the hacked files rather than repairing them. Ask for the answers in writing: what was replaced, which users and Search Console owners were removed, and how the hacker got in. The first-day steps for any hack are in what to do if your website is hacked.

Tell us what you need built

A few lines about your project are enough to start. We'll reply with questions, a sensible next step and, where the job allows, a fixed price.

Great service deliverables - Supportive, patient, reachable at all times and responsive

Samantha M. · Xscape4u · Google review