WordPress hacked redirect: find, fix, and prevent spam redirects
How to find WordPress spam redirects in .htaccess, index.php, siteurl/home, posts, and uploads, clean the infection, and harden the site against a return.
Topics Malware & cleanup
Security advisorywp2shell: WordPress core vulnerability. Updated August 4, 2026.
Read the advisoryHow to find WordPress spam redirects in .htaccess, index.php, siteurl/home, posts, and uploads, clean the infection, and harden the site against a return.
Topics Malware & cleanup
A WordPress hacked redirect sends visitors (or only some of them) to spam, phishing, or malware sites instead of your content. Sometimes every request bounces before your theme loads. Sometimes only mobile users, search traffic, or a single injected link is affected. Either way, treat it as an active malware incident, not a “SEO tweak.”
Act quickly. Redirects burn trust, trigger Safe Browsing warnings, and can get the host to suspend the account so neighbors on the server stay clean.
Attackers look for the usual openings: outdated plugins and themes, weak or reused admin passwords, nulled packages, and exposed file upload bugs. After they get in they may:
Redirects do not always hit the homepage only. They can sit on a landing page link, in a footer script, or in conditional code that fires for Googlebot or phones only. That is why “it looks fine when I visit” is a weak all-clear.
Background reading: why small sites get attacked and signs your WordPress site is hacked.

Attack. Source: Giphy.
Check these locations in order. Many incidents use more than one.
.htaccessLook for unexpected RewriteRule / RewriteCond blocks, redirects to unknown domains, or auto_prepend_file / auto_append_file tricks. Compare with a clean default for your permalink setup. Malicious rules often sit at the top or bottom of the file.
index.php (web root and theme)WordPress root index.php should be short and standard. Extra header('Location:...'), eval, or remote includes are red flags. Theme header.php, footer.php, and functions.php get the same treatment.
siteurl and home optionsIn Settings → General, confirm WordPress Address and Site Address. Attackers also change siteurl / home directly in the database (wp_options). Wrong values send the whole admin or front end to another host.
You can inspect with WP-CLI when you have shell access:
wp option get siteurl
wp option get home
Reset them to your real HTTPS URLs if they were altered.
Search posts, pages, widgets, and theme options for <script> tags, window.location, or obfuscated base64 blobs you did not add. Page builders and “custom HTML” widgets are frequent plant points.
Scan wp-content/uploads/ for .php files and recently modified assets that load remote scripts. A single webshell can reinject redirects after you clean the theme.
Malicious code in wp_options, unexpected cron events, and unknown admin users keep redirects alive after a partial cleanup. Pair file cleanup with a user audit.
Manual file review is possible if you know the tree well. It is slow and easy to miss conditional redirects. Use scanners, then verify the high-risk paths by hand.
Do not leave a “mostly cleaned” site public. Finish persistence removal, then reopen. That is how you stop WordPress hacked redirects from owning your traffic and your reputation.
Found this useful? Share it.