How to Fix WordPress Redirect Hack (2026 Complete Guide)
Learn how to fix WordPress redirect hacks and remove malware safely. Step-by-step guide to detect malicious redirects and secure your website.
Have you ever opened your WordPress website and suddenly been sent to a completely different website?
Maybe it redirects to a gambling page, a spam website, a fake shopping page, or a suspicious advertisement.
Even stranger, the website may look perfectly normal when you visit it.
But a customer using Google Search might get redirected somewhere else.
If that sounds familiar, your WordPress website may have been compromised by a redirect hack.
The good news is that a redirect does not always mean your entire website needs to be rebuilt. In many cases, you can find the malicious code, remove the infection, secure the original entry point, and verify that the redirect is gone.
In this guide, I'll walk you through how to identify a WordPress redirect hack, where to look for hidden malware, how to clean the website safely, and what to do afterward to reduce the chance of another infection.
Quick answer: A WordPress redirect hack usually happens when malicious code is injected into your website's files, database, .htaccess, plugin/theme code, or another compromised component. Cleaning only the visible redirect is not enough—you need to find the underlying infection and verify that it has been removed.
🚨 Is Your WordPress Website Redirecting Visitors?
Before changing anything, confirm what is actually happening.
A compromised website does not always behave the same way for everyone.
You may notice things like
- Your homepage opens normally for you.
- Some visitors are redirected to another website.
- The redirect happens only on mobile devices.
- The redirect appears only when someone comes from Google.
- A redirect happens only for first-time visitors.
- Strange spam pages appear in Google Search.
- Your organic traffic suddenly drops.
- Customers tell you that your website is showing something strange.
This behavior can make a redirect hack surprisingly difficult to notice.
If the website looks normal when you are logged in, don't assume everything is clean.
Try checking the website in an incognito/private browser window and, if possible, from another device or network.
What Is a WordPress Redirect Hack?
A WordPress redirect hack happens when an attacker gains access to a website and adds malicious code that sends visitors somewhere they did not intend to go.
The destination could be:
- A spam website
- A gambling website
- A fake shopping page
- A phishing page
- An adult spam page
- A malware download page
- Another website controlled by the attacker
The malicious code can be placed in different parts of WordPress.
For example, an attacker may modify:
- WordPress files
- Plugin files
- Theme files
- .htaccess
- Database content
- Uploaded files
- Injected JavaScript
- A malicious backdoor
That's why simply removing one redirect URL does not necessarily fix the infection.
You need to find how the redirect is being generated and whether anything else was left behind.
How Does a WordPress Redirect Hack Happen?
There isn't always one single cause.
Common entry points include:
1. Outdated Plugins
An outdated plugin may contain a known security vulnerability that attackers can exploit.
2. Vulnerable Themes
Themes can also contain vulnerabilities, especially when they are old or poorly maintained.
3. Weak or Reused Passwords
If an administrator account is compromised, an attacker may be able to install malicious code or modify existing files.
4. Pirated or “Nulled” Plugins and Themes
Unofficial copies of premium software are particularly risky because you cannot reliably know what has been added to the package.
5. Compromised Hosting or Another Access Point
The initial compromise may not always be obvious from WordPress itself. Hosting access, FTP credentials, stolen administrator credentials, or another compromised component can also become an entry point.
Once an attacker gets access, they may leave behind a backdoor so they can return later.
🔍 Common Signs of a WordPress Redirect Hack
Here are some of the most common warning signs.
1. Visitors Report Strange Redirects
A customer tells you:
“Your website sent me somewhere else.”
Don't ignore this simply because the website works normally on your computer.
Try reproducing the issue using an incognito/private window.
2. Your Google Traffic Suddenly Drops
A malicious redirect can create a poor experience for visitors and may also be associated with spam pages or other SEO problems.
A sudden traffic drop doesn't automatically prove that your site is hacked, but if it happens together with strange redirects or unexpected search results, it deserves investigation.
3. Strange URLs Appear in Google
You can perform a basic search like
site: yourdomain.com
Look through the results.
If you suddenly see pages, titles, or URLs that you never created, investigate further.
For example, you might find:
- Random spam pages
- Gambling-related keywords
- Unusual foreign-language pages
- Fake product pages
- Strange URL patterns
4. Unknown Files Appear Inside WordPress
Attackers may upload or modify files to maintain access.
Folders that deserve attention during an investigation can include:
/wp-content/uploads/
/wp-admin/
/wp-includes/
However, don't delete a file just because its name looks unfamiliar.
WordPress and plugins can contain legitimate files that may look unusual to someone who hasn't worked with them before.
A suspicious file should be verified before removal.
How to Check If Your WordPress Site Is Really Hacked
Before you start deleting files, take a moment to investigate.
A useful investigation looks at more than one area.
Check 1 — Test the Redirect
Try:
- Logged-out browsing
- Incognito/private browsing
- Mobile device
- Desktop browser
- Another internet connection, if possible
If the redirect only happens under certain conditions, document that behavior.
Check 2—Search Google
Use:
site: yourdomain.com
Look for unexpected pages or search snippets.
Also check whether Google Search Console reports unusual indexing or security-related issues.
Check 3 — Run a Security Scan
A WordPress security plugin such as Wordfence can help identify suspicious files or modifications.
External scanners such as Sucuri SiteCheck can provide another perspective.
But remember:
A clean result from one scanner does not automatically prove that the website is completely clean.
A good investigation combines automated scanning with manual checks.
What to Do Immediately If Your Website Is Redirecting
If the redirect is happening right now, don't start randomly deleting files.
Do these things first:
1. Create a Backup
Take a backup of:
- Website files
- Database
- Important configuration files
Even if the website is infected, preserving the current state can be extremely useful during investigation.
2. Document the Problem
Record:
- The redirect destination
- Which pages redirect
- Whether mobile is affected
- Whether Google visitors are affected
- When you first noticed the problem
3. Avoid Random File Deletion
A strange-looking PHP file is not automatically malware.
Verify it before removing it.
4. Prepare for a Full Investigation
Redirect malware can exist in more than one location.
Checking only the homepage or only .htaccess may leave the actual infection behind.
Step-by-Step: How to Fix a WordPress Redirect Hack
Now let's move into the cleanup process.
Step 1—Back Up the Website Before Cleanup
Before making changes, create a backup of both the website files and database.
At minimum, keep:
- A copy of the WordPress files
- A database backup
- A local copy, if possible
Plugins such as UpdraftPlus or All-in-One WP Migration can be used for backups, depending on your setup.
The important thing is not the particular plugin.
The important thing is having a recoverable copy before you start making changes.
Step 2—Scan the Website for Malware
Start with a reputable WordPress security scanner.
Common options include
- Wordfence
- Sucuri SiteCheck
- MalCare
A scan can help identify:
- Modified core files
- Suspicious plugin files
- Malicious PHP
- Known malware patterns
- Unexpected file changes
But don't stop there.
Some infections are difficult for automated scanners to identify, especially when the malicious code is hidden, modified, or stored somewhere unexpected.
That's why manual investigation still matters.
Step 3 — Inspect Suspicious Files Carefully
Look through areas such as
/wp-content//wp-content/uploads//wp-admin//wp-includes/
You're looking for things such as
- Unexpected PHP files
- Recently modified files
- Files that don't belong to a plugin/theme
- Obfuscated code
- Suspicious scripts
- Backdoors
You may encounter functions or patterns such as
base64_decode()
eval()gzinflate()
These functions are not automatically proof of malware.
Legitimate software can use various coding techniques, so context matters.
Compare suspicious files against a clean copy of the same WordPress version, plugin, or theme whenever possible.
Step 4—Check the .htaccess File
The .htaccess file can contain legitimate rewrite rules, but attackers can also modify it to create unwanted redirects.
A suspicious rule might look like
RewriteRule . * https://example-spam-site.com [R,L]
The exact malicious code can vary.
Don't delete the entire .htaccess file just because you suspect a redirect.
First:
1. Keep a backup.2. Review the rules.3. Compare them with a clean WordPress configuration where appropriate.4. Remove only confirmed malicious entries.5. Test the website afterward.
Step 5—Check the Database for Injected Content
Not every redirect is stored inside a PHP file.
Malicious content can also be injected into the WordPress database.
Depending on the infection, areas such as these may require investigation:
wp_optionswp_posts
You may find:
- Injected JavaScript
- Hidden iframe code
- Spam content
- Suspicious URLs
- Unexpected settings
- Malicious snippets
Database cleanup should be done carefully.
Before editing database records, create a database backup and make sure you understand exactly what you're changing.
Step 6 — Remove the Infection, Not Just the Redirect
This is where many quick cleanup attempts go wrong.
Suppose you remove the redirect from .htaccess.
The website works again.
You might think:
"Done!"
But what if the attacker also left a backdoor somewhere else?
The redirect can come back.
That's why proper cleanup should look for the source of the infection, not just the visible symptom.
Depending on what you find, remediation may involve:
- Removing malicious files
- Restoring modified core files
- Reinstalling compromised plugins/themes from trusted sources
- Cleaning injected database content
- Removing unauthorized administrator accounts
- Resetting credentials
- Removing persistence mechanisms
The exact cleanup method depends on the evidence.
Step 7—Update and Harden WordPress
Once the infection has been cleaned, don't stop there.
Update:
- WordPress core
- Plugins
- Themes
Remove:
- Unused plugins
- Unused themes
- Pirated/nulled software
- Components you no longer need
Then improve the site's security.
Consider:
- Strong unique passwords
- Two-factor authentication
- Firewall protection
- Login protection
- Regular backups
- File-change monitoring
- Least-privilege user accounts
Security is not just about removing today's malware.
It's also about reducing the chance of the same problem happening again.
How to Verify That the Redirect Hack Is Gone
Cleaning files is only half the job.
You also need to verify the result.
After cleanup, test the website again.
Check the redirect.
Open the site:
- Logged in
- Logged out
- In an incognito window
- On mobile
- On desktop
Check important URLs.
Test:
- Homepage
- Main service pages
- Blog posts
- Contact page
- Other important landing pages
Run another security scan.
Run your security scanner again after cleanup.
The goal is not simply to get a “clean” message.
You want to see whether the suspicious findings that led to the investigation have actually been resolved.
Check Google
Search:
site: yourdomain.com
Look for unexpected spam pages or strange URLs.
If your site had serious SEO spam or indexing problems, recovery in Google may take additional time even after the underlying infection has been fixed.
Why Redirect Malware Can Come Back
If the redirect returns after cleanup, don't simply remove the same code again.
Ask:
How did it get back?
Possible reasons include:
- A hidden backdoor remains.
- Another infected file was missed.
- A compromised plugin/theme is still installed.
- An administrator account is still compromised.
- Hosting credentials were exposed.
- The database still contains malicious code.
- The original vulnerability remains open.
This is why a proper malware cleanup is also an investigation into the root cause and persistence of the infection.
How to Prevent Another WordPress Redirect Hack
You don't need a complicated security setup to start improving your WordPress security.
Focus on the basics:
Keep WordPress Updated
Update WordPress core, plugins, and themes regularly.
Use Trusted Software
Avoid pirated or nulled themes and plugins.
Protect Administrator Accounts
Use strong, unique passwords and enable 2FA where possible.
Use Security Monitoring
A reputable security plugin can help monitor files, login activity, and other suspicious behavior.
Maintain Backups
Keep regular backups and make sure you know how to restore them.
Remove Unused Software
If you don't need a plugin or theme, remove it instead of leaving it installed indefinitely.
Monitor Your Website
Regularly check:
- Unexpected files
- New administrator accounts
- Strange redirects
- Google Search results
- Security scan results
A few minutes of monitoring can help you notice a problem before it becomes a major incident.
A Practical Lesson From Real WordPress Security Work
A compromised website does not always look obviously broken.
In real WordPress security investigations, suspicious behavior may be hidden behind normal-looking pages, while the actual evidence appears in places such as
- Source code
- Security scan results
- Modified files
- Database entries
- Search engine results
That's why I prefer looking at multiple sources of evidence instead of relying on one scanner or one visible symptom.
Important: Only use your actual case-study screenshots in this section if they directly support the point being discussed. Don't present a malware screenshot from another type of incident as evidence of a redirect hack.
When Should You Get Professional Help?
You may be able to handle a simple issue yourself if you understand exactly what you're changing and have a reliable backup.
Professional help becomes more useful when:
- The redirect keeps coming back
- Multiple files are infected
- You find a backdoor
- Unknown admin accounts appear
- The database contains injected code
- Google has indexed large amounts of spam
- You cannot identify the original entry point
- The website is business-critical
- You are not comfortable modifying PHP files or the database
In those situations, the goal should not be just:
“Make the redirect disappear.”
The goal is:
Detect → Investigate → Clean → Verify → Secure
Frequently Asked Questions
Can a WordPress redirect hack affect only mobile visitors?
Yes. Malicious redirect code can be configured to behave differently depending on the visitor, device, browser, referrer, or other conditions. This can make the infection harder to detect.
Why does my website look normal when I'm logged in?
Some malware uses conditional behavior. It may show the normal website to administrators while redirecting other visitors.
That is why testing logged-out and incognito sessions is useful.
Is .htaccess always responsible for WordPress redirects?
No.
A redirect can originate from .htaccess, WordPress files, plugins, themes, the database, injected JavaScript, or another compromised component.
Should I delete every unknown PHP file?
No.
An unfamiliar filename is not enough evidence to call a file malicious. Verify the file before deleting it.
Can a WordPress security plugin remove a redirect hack automatically?
Sometimes a security plugin can detect or remove certain malicious files, but automated scanning should not be treated as a guarantee that every part of an infection has been removed.
Will cleaning the malware immediately restore my Google rankings?
Not necessarily.
Removing the infection is an important first step, but search visibility can take time to recover depending on what happened to the website and how Google processes the changes.
What if the redirect comes back after cleanup?
Treat that as a sign that something may have been missed or the original access point may still be open.
Investigate files, databases, users, plugins, themes, credentials, and other possible persistence mechanisms rather than repeatedly deleting the visible redirect.
Final Thoughts
A WordPress redirect hack can be scary, especially when your website looks completely normal from your own computer.
But don't panic and start deleting random files.
Start with evidence.
Back up the website.
Confirm the behavior.
Scan and investigate the files, database, and configuration.
Remove the actual infection.
Verify the website again.
Then harden it.
The most important lesson is simple:
Fixing the redirect is not the same as fixing the hack.
If the underlying infection remains, the redirect can return.
Need Help With a Hacked WordPress Website?
If your WordPress website is showing strange redirects, spam content, suspicious files, or other signs of compromise, I can help with:
- WordPress malware removal
- Redirect hack cleanup
- Hacked website recovery
- Security investigation
- WordPress security hardening
- Post-cleanup security checks
If you need help, you can contact me for a website security assessment.
You may also find these guides useful:
- What to Do If Your WordPress Site Gets Hacked? 7 Simple Steps to Fix It
- How to Remove Japanese Keyword Hack from WordPress
- How to Fix “Error Establishing a Database Connection” in WordPress
- How to Fix White Screen of Death in WordPress







