You enter your website address expecting to see your homepage.
Instead, the browser sends you somewhere else.
Sometimes the redirect happens every time. Sometimes it happens only on mobile devices, only for visitors arriving from Google, or only when someone is not logged in.
This behavior is commonly associated with a WordPress redirect hack.
A malicious redirect can affect visitors, search visibility and the reputation of a website. More importantly, the redirect is usually a symptom of a larger compromise rather than the complete problem.
Removing the visible redirect without finding the code, account, configuration or persistence mechanism responsible for it can allow the problem to return.
What Is a WordPress Redirect Hack?
A WordPress redirect hack occurs when unauthorized code or configuration causes visitors to be sent from the legitimate website to an unintended destination.
The destination may be a spam website, phishing page, fake security warning, unwanted advertisement or another malicious website.
Not every redirect is malicious. WordPress websites legitimately use redirects for URL changes, HTTPS enforcement, canonical URLs and other purposes.
The security concern begins when a redirect occurs without authorization or behaves differently from the website owner’s intended configuration.
Why Redirect Hacks Are Difficult to Detect
A well-designed malicious redirect does not necessarily affect every visitor.
Attackers can use conditions to reduce the chance of detection.
- Only mobile visitors are redirected.
- Only logged-out visitors are redirected.
- Only visitors from search engines are redirected.
- Only specific IP addresses are targeted.
- The redirect happens only on the first visit.
- The destination changes over time.
- Administrators may see the normal website.
This selective behavior has been documented in WordPress malware cases and security research. Sucuri has reported malicious redirects triggered by conditions such as user agents, referrers and IP addresses. [oai_citation:0‡Sucuri](https://www.sucuri.net/reports/Sucuri-Hacked-Report-2017.pdf?utm_source=chatgpt.com)
What Does a WordPress Redirect Hack Look Like?
The symptoms can vary considerably.
- Your homepage redirects to an unrelated website.
- Only certain pages redirect.
- Mobile users see a different destination.
- Google visitors are redirected while direct visitors are not.
- The website works normally for administrators.
- A fake browser or security warning appears.
- Visitors are sent to spam or gambling websites.
- The redirect appears only once per visitor.
- The destination changes between visits.
These symptoms should be investigated rather than assumed to have a single cause.
First: Confirm That the Redirect Is Actually Unauthorized
Before searching for malware, establish what the redirect is doing.
Check whether the redirect is expected because of:
- A website migration
- An old URL
- HTTPS configuration
- A canonical URL change
- A plugin configuration
- A content management rule
- A server configuration
- A CDN or proxy configuration
WordPress provides legitimate redirect functions and mechanisms, so a redirect by itself is not evidence of compromise. For example, wp_safe_redirect() is designed to perform controlled redirects to allowed hosts. [oai_citation:1‡WordPress Developer Resources](https://developer.wordpress.org/reference/functions/wp_safe_redirect/?utm_source=chatgpt.com)
The investigation becomes a security incident when the redirect is unexpected, unauthorized or associated with other indicators of compromise.
Why a Redirect Can Be a Security Incident
A malicious redirect can expose visitors to websites that the legitimate owner never intended to promote or operate.
Depending on the campaign, visitors may encounter:
- Phishing pages
- Fake security alerts
- Fraudulent software downloads
- Spam advertisements
- Scam websites
- Malicious content
Recent security reporting has documented WordPress infections where injected JavaScript was used to redirect visitors to scam domains. Sucuri’s research also documented redirect campaigns using DNS TXT records to dynamically obtain redirect destinations. [oai_citation:2‡Sucuri](https://sucuri.net/wp-content/uploads/2024/06/2023-Hacked-Website-Malware-Threat-Report.pdf?utm_source=chatgpt.com)
Where Can a WordPress Redirect Hack Hide?
There is no single file that should always be checked.
A malicious redirect can originate from several parts of the website or hosting environment.
| Location | What to Investigate |
|---|---|
| Theme files | Unexpected PHP or JavaScript modifications. |
| Plugins | Modified or unauthorized plugin code. |
| Database | Injected scripts, URLs or configuration values. |
| .htaccess | Unexpected server-side redirect rules. |
| wp-config.php | Unauthorized configuration changes. |
| mu-plugins | Unexpected automatically loaded code. |
| Uploads | Unexpected executable files. |
| User accounts | Unauthorized privileged access. |
| Scheduled tasks | Mechanisms that recreate malicious files or settings. |
| Hosting configuration | Redirects or access outside WordPress. |
The exact location depends on the infection.
1. Check the Theme Files
Theme files can contain PHP and JavaScript that execute when visitors load the website.
Investigate unexpected changes in files that participate in page generation, including commonly used theme files.
Do not search only for the word “redirect.” Malicious code can construct a destination dynamically, obfuscate strings or execute through another function.
File comparison against a known legitimate theme version can be more useful than searching for one specific keyword.
2. Check Plugins
A compromised plugin can provide a convenient place for malicious code to execute.
Review:
- Recently installed plugins
- Outdated plugins
- Abandoned plugins
- Plugins from untrusted sources
- Unexpected plugin files
- Unexpected modifications to legitimate plugin files
If a plugin is suspected, replacing it with a verified version may be safer than attempting to manually remove individual malicious lines from the code.
3. Inspect the Database
One of the most important lessons from redirect investigations is that the malicious code may not be entirely file-based.
Malicious URLs or scripts can be stored in database records and later loaded into the website.
Areas that may require investigation include:
- WordPress options
- Posts
- Post metadata
- Widgets
- Plugin settings
- Theme settings
- Custom fields
Security researchers have documented WordPress malware that hid redirect functionality inside database options while also creating hidden administrator accounts. [oai_citation:3‡WordPress.org](https://wordpress.org/support/topic/new-malware-found-in-wordpress-installations-hidden-admin-users-redirects-and/?utm_source=chatgpt.com)
This is one reason a clean file scan does not automatically prove that a redirect infection has been removed.
4. Inspect .htaccess Carefully
The .htaccess file can influence how Apache handles requests before WordPress renders the page.
Unexpected redirect rules in this file can therefore affect visitors without placing obvious redirect code inside a WordPress theme.
Historical Sucuri research documented malicious .htaccess signatures associated with spam SEO, phishing and conditional redirects. [oai_citation:4‡Sucuri](https://www.sucuri.net/reports/Sucuri-Hacked-Report-2017.pdf?utm_source=chatgpt.com)
Do not replace .htaccess blindly. First determine which rules are legitimate for the website and hosting environment.
5. Check Must-Use Plugins
Must-use plugins can be loaded automatically by WordPress and may not appear in the normal plugin workflow used by less experienced administrators.
For this reason, a redirect investigation should include the relevant must-use plugin directory when it exists.
Unexpected files in this location should be investigated against the known configuration and deployment history of the website.
6. Review Administrator Accounts
A redirect may be only one part of a broader compromise.
Review administrator accounts for:
- Unknown users
- Recently created users
- Unexpected email addresses
- Unexpected administrator roles
- Unusual account activity
Security research has documented malware capable of creating hidden administrator accounts while simultaneously performing conditional redirects. [oai_citation:5‡WordPress.org](https://wordpress.org/support/topic/new-malware-found-in-wordpress-installations-hidden-admin-users-redirects-and/?utm_source=chatgpt.com)
Therefore, removing a redirect without checking privileged accounts can leave an attacker with another route back into the website.
7. Investigate Scheduled Tasks
If a redirect disappears after cleanup and then returns, look for persistence.
Scheduled tasks can potentially recreate files or database changes after they have been removed.
Recent WordPress security case reporting has documented situations where repeated malware reinfection was traced to a scheduled task that continued writing malicious content back to the website. [oai_citation:6‡WP Security Ninja](https://wpsecurityninja.com/malware-kept-coming-back/?utm_source=chatgpt.com)
This is why repeated cleanup without investigating what is recreating the malware can become an endless cycle.
Why the Redirect May Happen Only on Mobile
Conditional redirects are particularly effective at avoiding detection.
An attacker may configure the malicious code to behave differently according to the visitor’s characteristics.
- User agent
- IP address
- Referrer
- Login status
- Cookies
- Geographic location
- Request frequency
Security research has documented redirect malware using conditions such as user agent, referrer and IP address. [oai_citation:7‡Sucuri](https://www.sucuri.net/reports/Sucuri-Hacked-Report-2017.pdf?utm_source=chatgpt.com)
Why You May Not See the Redirect When Logged In
Some malicious redirect campaigns deliberately exclude administrators.
This allows the website owner to see a normal dashboard and homepage while ordinary visitors receive the malicious response.
A documented WordPress malware example used a condition based on login status and redirected non-logged-in visitors while leaving logged-in users unaffected. [oai_citation:8‡WordPress.org](https://wordpress.org/support/topic/new-malware-found-in-wordpress-installations-hidden-admin-users-redirects-and/?utm_source=chatgpt.com)
For that reason, testing only while logged into WordPress is not enough.
Test the Website From Multiple Perspectives
When investigating an intermittent redirect, test the website using different conditions.
- Logged-in administrator
- Logged-out browser
- Private browsing session
- Desktop browser
- Mobile browser
- Different network connection
- Direct URL
- Search engine result
Record the exact URL, time, device, browser and destination whenever the redirect occurs.
This creates evidence that can help identify the conditions under which the malicious behavior is triggered.
Use External Testing Carefully
External testing can help reveal behavior that is not visible from the WordPress dashboard.
Website security services can inspect public responses, links and other externally visible indicators.
However, external scanning has limitations.
Sucuri’s own Unmask Parasites documentation notes that search engine results can be outdated and that Google searches cannot reveal every form of harmful content, including some malicious scripts and redirects. [oai_citation:9‡Unmask Sucuri](https://unmask.sucuri.net/security-tools/find-hidden-links/web/?utm_source=chatgpt.com)
Therefore, external scanning should be one component of the investigation rather than the only source of evidence.
Why a Security Scanner Can Say “Clean” While the Redirect Continues
This situation is possible and can be confusing.
A scanner may fail to identify a redirect because:
- The malicious code is heavily obfuscated.
- The behavior is conditional.
- The payload is generated dynamically.
- The redirect destination is obtained remotely.
- The malicious content is stored in the database.
- The scanner does not inspect a particular component.
- The redirect exists outside the WordPress application.
Recent malware research has documented dynamic redirect techniques that obtain destinations through DNS TXT records, demonstrating why a simple search for a hard-coded malicious URL may not be enough. [oai_citation:10‡Sucuri](https://sucuri.net/wp-content/uploads/2024/06/2023-Hacked-Website-Malware-Threat-Report.pdf?utm_source=chatgpt.com)
Do Not Just Search for the Redirect URL
Finding the destination URL inside a file can be useful, but it is not always possible.
A malicious redirect may construct its destination dynamically, encode strings, retrieve information from another source or use a legitimate-looking function to execute the redirect.
Searching for the visible destination is therefore only one investigation technique.
Check the Browser Response
Browser developer tools can provide useful evidence about what happens when the website is requested.
Depending on the type of redirect, useful information may include:
- HTTP status codes
- Location headers
- Loaded scripts
- Network requests
- Unexpected external domains
- Redirect chains
This can help distinguish a server-side redirect from one generated by JavaScript after the page begins loading.
Server-Side vs JavaScript Redirects
| Type | Typical Evidence |
|---|---|
| HTTP redirect | Redirect response and Location header. |
| PHP redirect | Server-side code producing redirect behavior. |
| JavaScript redirect | Script executes in the browser and changes location. |
| Database injection | Malicious content is loaded from stored data. |
| Server configuration | Redirect occurs before normal WordPress rendering. |
Identifying the mechanism helps narrow the investigation.
Check the WordPress Database for Suspicious URLs
If the redirect does not appear in the obvious PHP files, inspect relevant database content.
Look for unexpected domains, scripts or configuration changes in places where plugins and themes normally store settings.
Database investigation should always be performed carefully and preferably after creating a reliable backup.
Do Not Run Blind Search and Replace
Finding a malicious domain inside a database does not mean every occurrence should be replaced automatically.
The same string may appear in legitimate historical content, logs, documentation or serialized data.
Any database modification should account for WordPress data structures and, where relevant, serialized values.
What to Do Before Cleaning a Redirect Hack
Before making major changes, establish a recovery point and preserve useful information.
- Create a protected backup of the website files and database.
- Record the redirect destination.
- Record when and how the redirect occurs.
- Document affected pages and visitors.
- Review recent WordPress changes.
- Check administrator accounts.
- Review plugins and themes.
- Review relevant logs if available.
If the website is actively exposing visitors to malicious content, temporary measures to reduce visitor exposure may also be appropriate while investigation and cleanup are underway.
Do Not Assume Changing the Homepage Fixes the Problem
Changing the homepage content or removing one visible script may make the website appear normal while leaving the actual infection untouched.
The redirect may be generated elsewhere.
This is why the investigation should cover the relevant application, database and hosting layers.
How to Remove a WordPress Redirect Hack
There is no single cleanup procedure that is safe for every infected website.
A controlled remediation process normally follows this sequence:
- Preserve the affected environment.
- Identify the redirect mechanism.
- Determine the scope of compromise.
- Locate malicious code or configuration.
- Identify persistence mechanisms.
- Remove malicious components.
- Replace compromised legitimate components where appropriate.
- Remove unauthorized accounts.
- Rotate affected credentials.
- Fix the original vulnerability.
- Verify the website again.
The important part is not the order of one particular command. It is ensuring that the cleanup addresses both the visible redirect and the mechanism that allowed it to exist.
Why Removing the Redirect Is Not Enough
Suppose a malicious script is removed from a theme.
If an attacker still has a compromised administrator account, vulnerable plugin or scheduled task, the website can be modified again.
This is the difference between symptom removal and incident remediation.
Check for the Original Entry Point
Once the redirect has been identified, determine how unauthorized code could have entered the environment.
- Vulnerable plugin
- Vulnerable theme
- Compromised administrator account
- Compromised hosting credentials
- Untrusted software
- Weak authentication
- Exposed service
- Compromised third-party component
The evidence may not always prove the original entry point. A professional assessment should state clearly what is confirmed and what remains a hypothesis.
Rotate Credentials After a Confirmed Compromise
If unauthorized access is suspected, review credentials across the relevant environment.
- WordPress administrators
- Hosting control panel
- FTP or SFTP
- SSH
- Database
- API credentials
- Third-party integrations
Changing only one WordPress password may leave another access path available.
Update Vulnerable Components
Once the infection has been addressed, update supported WordPress core, plugins and themes to appropriate current versions.
If a vulnerable plugin or theme was the likely entry point, determine whether it should be replaced or removed instead of simply updating it.
Verify That the Redirect Is Gone
Do not verify the cleanup from one browser session.
- Test logged in.
- Test logged out.
- Test from a private browser session.
- Test desktop.
- Test mobile.
- Test important pages.
- Check redirect chains.
- Run appropriate security scans again.
Continue monitoring after cleanup because delayed or conditional behavior can otherwise be missed.
What If the Redirect Comes Back?
If the redirect returns after cleanup, do not simply repeat the same removal procedure.
Ask what is putting it back.
- Is another malicious file still present?
- Is the database still compromised?
- Is an unauthorized account active?
- Is a scheduled task recreating the code?
- Is the hosting account compromised?
- Is another website under the same account infected?
- Was the original vulnerability fixed?
Recent security case reporting has shown that recurring WordPress malware can sometimes be traced to scheduled tasks that reinject malicious code after the visible infection has been removed. [oai_citation:11‡WP Security Ninja](https://wpsecurityninja.com/malware-kept-coming-back/?utm_source=chatgpt.com)
When Should You Get Professional Help?
A professional investigation is worth considering when the redirect is persistent, conditional or repeatedly returns after cleanup.
- The redirect appears only for certain visitors.
- Security scanners cannot identify the cause.
- The website redirects again after cleanup.
- An administrator account was compromised.
- The database may be infected.
- The hosting provider has suspended the website.
- Google has flagged the domain.
- Multiple websites are affected.
- The website handles sensitive customer information.
- You cannot establish whether the website is clean.
WordPress Redirect Hack Investigation Checklist
| Area | Check |
|---|---|
| Browser | Record destination, timing and redirect behavior. |
| Users | Check for unauthorized privileged accounts. |
| Plugins | Review installed, inactive and modified plugins. |
| Themes | Compare important files with known legitimate versions. |
| Database | Look for unexpected URLs, scripts and configuration changes. |
| .htaccess | Review unexpected redirect rules. |
| MU plugins | Check automatically loaded components. |
| Uploads | Investigate unexpected executable files. |
| Scheduled tasks | Look for mechanisms that may recreate malicious content. |
| Hosting | Review logs and account-level access. |
| Recovery | Retest after cleanup from multiple perspectives. |
Final Perspective
A WordPress redirect is not always a malware infection.
But when visitors are unexpectedly sent to unrelated websites, the behavior deserves a proper security investigation.
The difficult part is often not finding the visible redirect. It is finding what caused it and what allows it to remain active.
A complete investigation should consider the WordPress files, plugins, themes, database, administrator accounts, configuration, scheduled tasks and hosting environment as appropriate.
Do not measure success by whether the homepage looks normal for one administrator session.
Measure success by whether the unauthorized redirect has been removed, the access path has been addressed and the website remains clean during verification.
Need Help With a WordPress Redirect Hack?
Cautivra provides remote WordPress malware investigation and cleanup for websites affected by unexpected redirects, malicious scripts, injected content, unauthorized accounts and recurring infections.
The assessment focuses on identifying the redirect mechanism, investigating the affected environment, removing malicious components and addressing the conditions that could allow the infection to return.
Request a WordPress Redirect Malware Assessment
Frequently Asked Questions
Why does my WordPress website redirect to another website?
An unexpected redirect can result from malicious code, modified configuration, compromised plugins, themes, database content or hosting-level changes. Legitimate redirects also exist, so the exact cause should be verified before classifying the behavior as malware.
Why does my WordPress site redirect only on mobile?
Malicious redirect campaigns can use conditions such as user agent, IP address or referrer to target particular visitors. However, mobile-specific behavior can also have legitimate configuration causes, so the behavior should be investigated rather than assumed to be malware.
Why does my WordPress site redirect only when I am logged out?
Some malicious redirect code deliberately excludes logged-in administrators so that the website appears normal during routine checks. This behavior has been documented in WordPress malware cases.
Why does the redirect return after I remove the malware?
Recurring redirects can indicate that another malicious component, compromised account, database entry, scheduled task or unresolved vulnerability remains. Repeated reinfection should trigger a broader investigation.
Can a WordPress security scanner miss a redirect hack?
Yes. A scanner has a defined scope and detection capability. Conditional redirects, dynamically generated destinations, database-based injections and behavior outside the scanner’s visibility can make detection more difficult. Multiple sources of evidence provide stronger coverage.
Should I delete the .htaccess file to stop a WordPress redirect?
Not blindly. The file may contain legitimate rules required by the website. Review the contents, identify unexpected changes and preserve a recovery copy before making modifications.
Sources and Further Reading
- WordPress Developer Resources:
wp_safe_redirect() - WordPress.org: Hacked Website Documentation
- Sucuri: Hacked Website and Malware Research
- Sucuri: Unmask Parasites
- WordPress Security Community Research