Emergency WordPress Hack Cleanup?
sales@inceptusdigital.com |
← Back to Insights

How to Fix Hacked WordPress Site Redirecting to Scam & Casino Ads: Step-by-Step Emergency Manual Cleanup Guide (2026)

Security
How to Fix Hacked WordPress Site Redirecting to Scam & Casino Ads: Step-by-Step Emergency Manual Cleanup Guide (2026)

If visitors to your WordPress website are being hijacked and sent to illicit casino, gambling, or fake tech-support scam pages, your site has been hit by the infamous WordPress Malware Redirect Hack. Hackers write sneaky conditional logic so site owners logged into the admin dashboard don't notice the redirect, while real mobile visitors or Googlebot get hijacked.

Symptom Check: Do You Have This Hack?

  • Direct traffic from mobile browsers gets redirected to random domain URLs.
  • Google search results show spam titles or foreign character indexation.
  • Google Chrome displays "The site ahead contains harmful programs" or Red Warning Screen.
  • Hosting provider sends account suspension emails due to high CPU usage or outbound spam scripts.

01. Understanding the Conditional Redirect Hack

The redirect payload is hidden behind User-Agent or Referrer checks. The malicious script evaluates whether the request comes from a search engine crawler (Googlebot, Bingbot) or a mobile device, and suppresses the payload if it detects an admin IP or logged-in WordPress session cookie.

To fix this permanently, you cannot simply clear browser cache or install a basic free security plugin. You must execute a complete, step-by-step manual server cleanup to purge every backdoor web shell.

02. Step 1: Emergency Server Isolation & SSH Backup

Connect to your web server via SSH or SFTP. Before modifying or deleting any files, create a full compressed backup of your site directory and MySQL database.

// 1. Compress public_html web directory into backup archive
tar -czvf infected_site_backup_$(date +%F).tar.gz /var/www/html/public_html
// 2. Export complete MySQL databasedump
mysqldump -u root -p database_name > infected_db_dump_$(date +%F).sql

03. Step 2: Locating Obfuscated Code & Web Shell Backdoors

Hackers inject base64-encoded strings and obfuscated PHP functions like eval(), gzinflate(), str_rot13(), and assert() deep into theme files, plugin folders, or rogue core files (e.g. wp-tmp.php, index.php.bak).

Run the following Linux grep commands in SSH from your web root to locate hidden backdoor web shells:

// Search for obfuscated base64 and eval code signatures
grep -rnEI "eval\s*\(\s*base64_decode" /var/www/html/public_html/
// Search for gzinflate and rot13 payload wrappers
grep -rnEI "gzinflate\s*\(|str_rot13\s*\(" /var/www/html/public_html/wp-content/
// Find all newly modified PHP files in the last 7 days
find /var/www/html/public_html/ -name "*.php" -mtime -7

04. Step 3: Surgical Cleaning of .htaccess & wp-config.php

The redirect hack often overrides your web server's .htaccess file with rewrite rules targeting malicious external C2 domain endpoints or proxy scripts.

Inspect .htaccess and replace its content with the default clean WordPress .htaccess setup:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Next, inspect wp-config.php. Hackers often insert an @include line at the very top of wp-config.php pointing to a hidden file in /tmp or /wp-includes/. Delete any suspicious require/include lines that precede <?php or define('DB_NAME'...).

05. Step 4: Database Audit & SQL Injected Payload Removal

Often, the malicious redirect JavaScript script tag is stored inside the database in wp_options (specifically siteurl, home, or active widgets) or inside wp_posts.

-- Check if siteurl or home options have been changed to spam domains
SELECT * FROM wp_options WHERE option_name IN ('siteurl', 'home');
-- Search for injected script tags in options
SELECT * FROM wp_options WHERE option_value LIKE '%<script%';
-- Audit wp_users table for rogue admin accounts
SELECT ID, user_login, user_email, user_registered FROM wp_users;

06. Step 5: Core Reinstallation & Uploads Execution Lock

Never try to selectively edit core files. Replace all core files from an official, fresh WordPress distribution:

  1. Delete /wp-admin/ and /wp-includes/ completely.
  2. Download fresh WordPress zip from WordPress.org and upload clean /wp-admin/ and /wp-includes/ folders.
  3. Delete all original files in root except wp-config.php, .htaccess, and wp-content directory.
  4. Block PHP script execution inside /wp-content/uploads/ by creating a .htaccess file inside uploads/ containing:
<Files *.php>
deny from all
</Files>

07. Step 6: Google Search Console Blacklist Removal

Once the malware payloads, web shell backdoors, and database entries are completely cleaned, log into Google Search Console.

  • Navigate to Security & Manual ActionsSecurity Issues.
  • Click Request Review.
  • Detail the exact remediation steps taken: core files replaced, database cleaned, PHP uploads execution disabled, and passwords reset.
  • Google typically reviews and removes the warning flag within 12 to 24 hours.

Need 24-Hour Emergency WordPress Malware Cleanup?

Don't risk site deletion or permanent domain penalization. Inceptus Digital provides 24-hour emergency WordPress malware cleanup, backdoor removal, and security hardening.

Get Emergency Cleanup Help →
Share this article

Need Custom Engineering or Growth Systems?

Our team helps ambitious brands build bespoke software, AI integrations, and high-conversion platforms.

Chat on WhatsApp