← All articles
Security

WordPress Redirect Hack: How to Find and Fix It

Learn how to identify a WordPress redirect hack, investigate malicious code, restore normal website behavior, and prevent the infection from returning.

zeyweb team·11 min read

If your WordPress website suddenly redirects visitors to spam pages, suspicious advertisements, or unfamiliar websites, it may be experiencing a security breach. This behavior is commonly associated with a WordPress redirect hack, where attackers inject malicious code into your website to control where visitors are sent.

Some redirect attacks are obvious: every visitor lands on an unrelated website instead of your homepage. Others are more difficult to detect because they only affect mobile users, visitors arriving from Google, or specific pages.

The biggest mistake is fixing the visible redirect without investigating its source. Malicious scripts, infected plugins, database injections, and hidden backdoors can continue operating even after the redirect appears to disappear.

In this guide, you'll learn how to identify a WordPress redirect hack, find its source, remove the infection, and prevent the problem from returning.

Because attackers may use hidden backdoors to maintain access after an initial infection, learn how to find and remove WordPress backdoors before considering the cleanup complete.

Common Signs of a WordPress Redirect Hack

Common Signs of a WordPress Redirect Hack

A redirect hack does not always affect every visitor in the same way. Attackers often use conditional logic to make their activity harder to identify.

Here are the most common warning signs.

Unexpected redirects to spam websites

Visitors attempting to access your website are redirected to unfamiliar domains, advertising pages, suspicious downloads, or other unrelated destinations.

Redirects affecting only mobile users

Your website may work normally on desktop computers while mobile visitors are sent to suspicious websites. Some malicious scripts specifically target mobile devices to avoid detection during routine checks.

Redirects from Google search results

A visitor clicks your website in Google and lands on a completely different page. This can happen when malicious code detects visitors arriving through search engines.

Specific pages redirecting unexpectedly

Your homepage may work normally while individual blog posts, product pages, or landing pages redirect visitors elsewhere.

Multiple redirects before reaching a destination

Instead of sending visitors directly to a malicious website, attackers may use several intermediate domains to hide the final destination.

Unexplained traffic and ranking changes

A compromised website may experience unusual traffic patterns, unexpected search results, or declining organic visibility.

If you notice any of these symptoms, investigate the possibility of a security breach rather than treating the problem as an ordinary WordPress configuration issue.

For a more hands-on cleanup process, learn about manual WordPress malware removal without a plugin to investigate infected files and remove malicious code.

Why Is Your WordPress Website Redirecting Visitors?

A WordPress redirect hack can originate from several parts of your website. Understanding the possible entry points makes it easier to identify the infection and prevent reinfection.

Malicious Code Injected into PHP Files

Attackers may modify WordPress core files, theme files, or plugin files to execute unauthorized redirects.

The injected code may be hidden among legitimate functions or written in an obfuscated format that makes it difficult to recognize.

Infected Themes and Plugins

Outdated plugins and themes can contain vulnerabilities that allow attackers to upload files or modify existing code.

Compromised or unofficially distributed themes and plugins can also introduce malicious scripts directly into a WordPress installation.

Modified .htaccess File

The .htaccess file controls certain server-level behaviors, including URL rewriting and redirects on Apache-based hosting environments.

Attackers may add malicious rules that send visitors to external domains under specific conditions.

However, not every unexpected redirect originates from this file. Removing unfamiliar rules without understanding their purpose can also break legitimate website functionality.

Malicious Database Injections

WordPress stores important website information in its database, including content, settings, and plugin-related data.

Attackers may inject malicious scripts into database records, modify website URLs, or alter settings that affect how visitors are redirected.

Hidden Backdoors

A backdoor allows attackers to maintain unauthorized access to your website.

Even if the visible redirect code is removed, a backdoor may allow the attacker to inject it again. This is one of the main reasons redirect problems frequently return after incomplete cleanup.

Vulnerable WordPress Components

Outdated WordPress installations, plugins, themes, and server software can expose weaknesses that attackers exploit.

A redirect hack may be the result of a vulnerability that was never properly addressed.

How to Find the Source of a WordPress Redirect Hack

Before changing files or deleting suspicious components, investigate how and when the redirect occurs.

A structured investigation helps distinguish between malicious code, legitimate redirect rules, and configuration problems.

If Google flags your compromised website as dangerous, follow this guide on how to get a website delisted from Google's blacklist.

Test the Website Across Different Devices

Open your website using different browsers and devices.

Check whether the redirect affects:

  • Desktop and mobile visitors.
  • Visitors arriving directly versus through Google.
  • The homepage versus individual internal pages.
  • Logged-in versus logged-out users.

These differences can reveal conditional redirect behavior.

For example, if only mobile visitors are redirected, the malicious code may contain device-detection logic.

Check Google Search Console

Google Search Console can help identify security problems affecting your website's search presence.

Review the Security Issues and Manual Actions reports. Look for warnings involving hacked content, malware, or suspicious pages.

Also inspect unexpected URLs appearing in search results. Japanese spam pages, unfamiliar product pages, and unrelated landing pages may indicate a broader compromise.

Remember that not every redirect hack produces a Google security warning. A clean report does not prove that your website is safe.

Inspect WordPress Core Files

Compare your WordPress core files against clean versions of the same release.

Pay attention to unexpected changes in important files and unfamiliar PHP scripts in directories where they do not normally belong.

Look for suspicious code that executes redirects, loads external scripts, or behaves differently depending on visitor information.

Examine Plugins and Themes

Review recently modified files and investigate plugins or themes that were installed, updated, or changed shortly before the redirect began.

Check for unfamiliar extensions and remove components that are unnecessary or no longer maintained.

Do not assume that every unfamiliar file is malicious. Some plugins legitimately create additional files, so changes should be verified against trusted versions.

Inspect the Database

Check website settings, suspicious content, injected scripts, and unexpected modifications to database records.

Pay particular attention to:

  • Site URL and home URL settings.
  • Unexpected JavaScript inside posts and pages.
  • Suspicious plugin configuration records.
  • Unauthorized changes to user accounts.
  • Malicious code stored in custom fields.

Review Server Logs

Server access and error logs can provide valuable information about suspicious requests, unauthorized file access, and unusual activity.

Look for unexpected requests to administrative endpoints, unfamiliar file uploads, and activity that occurred around the time the redirect first appeared.

Combining log analysis with file and database inspection provides a much clearer picture of the attack.

To reduce the risk of reinfection, perform a WordPress plugin vulnerability check and identify extensions that may expose your website to attackers.

How to Fix a WordPress Redirect Hack

Once you identify the likely source of the infection, you can begin the cleanup process.

The objective is not simply to stop the redirect. You must remove the malicious code, eliminate unauthorized access, and restore the affected website components.

Step 1: Create a Backup of the Compromised Website

Before making significant changes, preserve a copy of the current website, including its files and database.

Even an infected backup can be useful during an investigation because it contains evidence of the attack.

However, never assume that an old backup is clean. Verify it before using it to restore the website.

Step 2: Remove Malicious Code

Identify and remove injected scripts, unauthorized PHP files, malicious redirect rules, and other compromised components.

If legitimate WordPress core files have been modified, replace them with clean versions from a trusted source.

For plugins and themes, reinstall clean copies where possible rather than attempting to repair every suspicious modification manually.

Step 3: Clean the Database

Remove malicious scripts, unauthorized settings, injected content, and other changes introduced by attackers.

Preserve legitimate website data, including posts, products, customer records, and configuration settings.

Database cleanup must be performed carefully because incorrect changes can damage website functionality or remove important information.

Step 4: Review and Repair .htaccess

Inspect the .htaccess file for unfamiliar redirect rules and unauthorized modifications.

Compare its contents against the configuration expected by your hosting environment and WordPress installation.

Remove confirmed malicious rules while preserving legitimate server and website configurations.

Step 5: Replace Compromised Plugins and Themes

Update or reinstall affected plugins and themes using trusted sources.

Remove unused extensions and investigate any component that cannot be verified.

If the infection originated through an outdated plugin, simply removing the malicious code without addressing the vulnerability may leave the website exposed.

Step 6: Secure All Access Credentials

Change passwords for:

  • WordPress administrator accounts.
  • Hosting control panels.
  • FTP or SFTP accounts.
  • Database users.
  • Other connected services with website access.

Remove unauthorized users and review administrator permissions.

Also rotate relevant security keys and salts so existing authentication sessions cannot continue using potentially compromised credentials.

How to Stop Redirect Hacks from Returning

How to Stop Redirect Hacks from Returning

Removing the visible infection is only part of the recovery process. You must also eliminate the conditions that allowed the attack to happen.

Find and Remove Hidden Backdoors

Inspect the entire WordPress installation for unauthorized access mechanisms.

Check unexpected PHP files, suspicious scheduled tasks, modified plugins, and other persistence mechanisms.

If a backdoor remains, attackers may be able to restore the redirect even after a successful initial cleanup.

Keep WordPress Components Updated

Use supported versions of WordPress, plugins, and themes.

Remove abandoned extensions and avoid installing software from unofficial sources.

Updates are particularly important when security vulnerabilities have been publicly disclosed.

Restrict Administrator Access

Limit administrator privileges to people who genuinely need them.

Use unique passwords, enable two-factor authentication, and review user accounts regularly.

Strengthen Hosting and File Security

Use secure file permissions and restrict unnecessary access to sensitive directories.

Ask your hosting provider about server-level security controls, malware monitoring, and protection against unauthorized file changes.

Enable Continuous Security Monitoring

Regularly monitor important website files, login activity, suspicious requests, and unexpected redirects.

A reliable security monitoring setup can help detect changes before they become another major incident.

How to Remove Google and Browser Security Warnings

A WordPress redirect hack can affect more than website functionality. If malicious redirects are detected by search engines or browser security systems, visitors may see warnings before reaching your website.

Restoring the website does not automatically remove every security warning.

Review Google Search Console

Open the Security Issues report in Google Search Console and examine the specific problems reported by Google.

Identify affected pages and determine whether the warning relates to malware, hacked content, or other suspicious behavior.

Remove the Underlying Infection

Before requesting a review, make sure the malicious code and unauthorized access mechanisms have been removed.

Check the homepage, internal pages, mobile behavior, and other areas that may have been affected.

Request a Security Review

Once the cleanup is complete, use the review process provided in Google Search Console.

Explain the security problem, describe the corrective actions taken, and confirm that the website has been secured.

Google needs to verify that the reported issues have been resolved before removing the relevant warning.

Check Other Browser Security Providers

Google is not the only organization that may identify a website as dangerous.

Check relevant security reputation services and follow their respective review procedures if your domain remains flagged.

Avoid submitting repeated review requests before the infection has been properly addressed.

When to Hire a Professional WordPress Malware Removal Service

When to Hire a Professional WordPress Malware Removal Service

Some redirect hacks are relatively simple, but others involve multiple infected files, database injections, hidden backdoors, and compromised hosting accounts.

Professional assistance becomes particularly important when:

  • Redirects continue after you modify .htaccess.
  • The problem disappears temporarily and then returns.
  • Only certain visitors or devices are affected.
  • You cannot identify the malicious code.
  • Google has flagged your website as dangerous.
  • Your website contains suspicious administrator accounts or unexpected files.
  • You suspect the hosting environment itself has been compromised.

A professional recovery process should investigate the complete website rather than focusing exclusively on the redirect destination.

This includes identifying the original entry point, removing malicious code, checking for persistent access, cleaning affected files and database records, and strengthening website security.

ZeyWeb provides website security and recovery services to help businesses deal with compromised WordPress websites.

If your website redirects visitors to spam pages or continues showing suspicious behavior after basic troubleshooting, ZeyWeb can help investigate the infection, remove malicious components, and restore your website's security.

The objective is to eliminate the underlying compromise rather than temporarily hide its symptoms.

FAQs About WordPress Redirect Hacks

Why does WordPress redirect to spam websites?

This usually happens when malicious code has been injected into your website. The code may be located in a theme, plugin, WordPress file, database record, or server configuration. Attackers use it to send visitors to advertising pages, spam websites, phishing pages, or other suspicious destinations.

Can a redirect hack affect only mobile visitors?

Yes. Some redirect malware checks the visitor's device type, browser, or referral source before executing. This allows attackers to target mobile visitors while making the website appear normal during desktop testing.

Does changing the .htaccess file fix the problem?

It may resolve a redirect if the malicious rule is located in .htaccess. However, the file may not be the original source of the infection. If malicious code remains elsewhere, the redirect can return. A complete investigation should include website files, database records, and possible backdoors.

Can a WordPress redirect hack return after cleanup?

Yes. Reinfection is possible if the original vulnerability remains or an attacker still has unauthorized access. Hidden backdoors, compromised administrator accounts, and outdated plugins are common reasons a redirect hack returns.

How do I know if my website is completely clean?

A successful recovery should include clean website files, an inspected database, secure administrator accounts, no remaining backdoors, and verified website functionality. External malware scans and Google Search Console checks can provide additional evidence, but neither alone guarantees complete cleanup.

Final Thoughts

A WordPress redirect hack can damage your website's reputation, expose visitors to malicious destinations, and negatively affect your search visibility.

The most effective solution is to identify the source of the redirect, remove the malicious code, investigate hidden backdoors, and secure every affected component.

Do not rely on changing a single configuration file or installing a scanner and assuming the problem is solved. If the original infection remains, the redirect may return.

If your WordPress website is redirecting visitors to spam or suspicious websites, ZeyWeb can help investigate the compromise, remove malware, and restore your website's security. A complete recovery protects more than your website's URLs: it helps protect your visitors, business reputation, and long-term search performance.

Written by the zeyweb team

Developers, designers and engineers who build, fix and support websites, apps and systems for businesses worldwide.

About us →

Responses