Codiffy (codiffy.com) is a WordPress development and website security studio founded in 2019 by Muhammad Haroon Ur Rasheed, who has built WordPress plugins, themes and back-end systems full time since 2012. Codiffy removes redirect hacks from WordPress and WooCommerce sites for businesses in the United States and Canada.
If your WordPress site sends visitors to a spam site, a hacker has almost certainly added code that does it. The redirect hides in one of five places: the .htaccess file, wp-config.php, your theme or plugin files, the siteurl and home settings in the database, or a script injected into posts and widgets. First rule out browser cache, then find and remove the code, and close the way the hacker got in, or the redirect comes back.
Need it fixed now? Call +1 (347) 474-0387, answered immediately, 24/7. We remove redirect hacks the same day, from $200. You get the fixed price in writing before we start. WordPress malware removal
How a WordPress redirect hack works
A redirect hack adds a few lines of code that send a visitor to another address. The other address is usually an ad page, a fake prize page, a casino or a fake “verify you are human” prompt. Google lists “redirects that send some visitors to harmful sites” as one form of hacked content in its spam policies.
Hackers rarely redirect everyone. If you, the owner, were redirected every time, you would fix it in an hour. So the code is conditional. Google notes that it can depend on the referrer, the user agent or the device. In practice that means:
- Only visitors who arrive from Google or social media are redirected.
- Only mobile visitors are redirected, so the site looks fine on your laptop.
- Only visitors who are not logged in are redirected, so you never see it in wp-admin.
- Only the first visit is redirected, then a cookie stops it, so a second look shows nothing.
This is why “it works for me” proves nothing.
Step-by-step overview
- Confirm the redirect is real and not browser cache.
- Check the site as a mobile visitor and as a Google visitor.
- Check .htaccess and wp-config.php.
- Check the database for changed URL settings and injected scripts.
- Check theme, plugin and upload files.
- Clean up, then close the way in.
Step 1: Confirm the redirect is real and not browser cache
Browsers remember permanent (301) redirects for a long time. If you once set up a redirect and later removed it, your browser may still follow the old one. Check before you assume a hack.
- Open the site in a private window and in a second browser you rarely use.
- Try another device on mobile data, not your office Wi-Fi.
- Clear the cache in your browser and, if you use one, in your caching plugin and Cloudflare.
- Disable browser extensions for a minute. A bad one can redirect pages on its own.
If the redirect shows on a device that has never opened your site, it is a real hack. If it only shows on one browser, it is cache or an extension on that machine.
Step 2: Check the site as a mobile visitor and a Google visitor
You can ask the server what it sends to different visitors. In a terminal, run these (replace the address):
curl -sIL https://example.com/
curl -sIL -A "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X)" -e "https://www.google.com/" https://example.com/
The first command acts like a plain visitor. The second acts like a phone visitor who came from Google. The Location: lines show where each one ends up. If the two commands end in different places, you have a conditional redirect. You can also use the URL Inspection tool in Google Search Console and view the crawled page to see what Google gets.
Step 3: Check .htaccess and wp-config.php
On Apache hosts, .htaccess in your site root is the most common hiding place. Download a copy first. A normal WordPress .htaccess is short and has a block between # BEGIN WordPress and # END WordPress. Look for:
RewriteCondlines that testHTTP_USER_AGENTorHTTP_REFERER, followed by aRewriteRuleto an address you do not own.- Long blocks of unfamiliar text, especially above or below the WordPress block.
- A
.htaccessfile in thewp-content,uploadsorpluginsfolders. These folders normally do not need one.
Open wp-config.php too. Anything above the line that says /* That's all, stop editing! */ should be settings you recognize. Long lines with base64_decode, eval or gzinflate, or code that runs before WordPress starts, are red flags.
Step 4: Check the database
The database is where redirects hide when files look clean.
- The siteurl and home settings. In Settings > General, both addresses should be your own. In phpMyAdmin, open the
wp_optionstable (your prefix may differ) and check the rowssiteurlandhome. If they point at a spam domain, the whole site redirects. - Injected scripts in posts and pages. Search
wp_postsfor<scriptand for<iframein thepost_contentcolumn. Real posts rarely contain either. - Widgets and theme settings. Look in
wp_optionsforwidget_custom_htmlandwidget_text. Scripts pasted into header and footer plugins live in options too.
With WP-CLI, wp option get siteurl and wp option get home check the first item in seconds.
Step 5: Check theme, plugin and upload files
functions.phpandheader.phpin the active theme. Look for code you did not add, especially anything obfuscated.index.phpandwp-settings.phpin the site root. These should match a fresh WordPress download.- Recently changed files. Sort by modified date and look at everything changed in the week the redirect began.
- Folders that should hold only images. PHP files in
wp-content/uploadsare almost always malware. - The mu-plugins folder. Must-use plugins load on every request and do not appear on the normal Plugins screen.
The safest method is to reinstall WordPress core and every plugin and theme from official copies, which overwrites tampered files. Keep your custom theme edits in a backup first.
A real case: pop-ups and redirects that came back
In October 2023, a family-owned tour company in Alberta asked Codiffy for urgent help when visitors began seeing spam pop-ups and redirects. We found malicious code in a core folder file and in index.php, a backdoor file in the site root, and a plugin the attacker was using to inject code. We removed all three.
The pop-ups came back. We traced them to a sister company’s website on the same hosting account, which was infected too. With the company’s approval we cleaned that site as well, reset every admin password, removed two admin accounts no one needed and set up two-factor login. One last flare-up on 1 November 2023 came from the same plugin and was fixed the same day.
If a redirect returns, look for a second infected site on the same hosting account and for a backdoor.
Another version is a fake Cloudflare page. At In Order to Succeed, a script sent visitors to a fake “verify you are human” check, a known trick to get visitors to run malware on their own computer. Guardian Shield Lite recognized and removed it. We found the same redirect on another site we built, Randy Clark & Associates.
Step 6: Clean up, then close the way in
- Back up the site first, including the database, and store the backup outside the public web folder.
- Remove the bad code you found in each place above. Do not delete a whole file unless you are sure it is not part of WordPress or a plugin.
- Reinstall core, plugins and themes from official sources, and delete any plugin you do not use.
- Change every password: WordPress admins, hosting, FTP or SFTP, the database, and email. Remove admin users you do not recognize, and replace the secret keys in wp-config.php.
- Find the way in. An outdated plugin or theme, a weak password, or a backdoor file. If you skip this, the redirect returns.
- Test again with the private window and the two curl commands from Step 2, then watch the site for a week.
Our complete guide, how to fix a hacked WordPress site, covers the whole cleanup in order.
How to stop it coming back
- Update WordPress, themes and plugins, and delete the ones you do not use.
- Use strong, unique passwords and two-factor login for every admin.
- Keep a scanner running that checks files and admin accounts. Codiffy’s care plans include Guardian Shield Lite.
- Do not put backups or
.zipcopies in the public web folder, where anyone can download them.
When to call a developer
Call for help if:
- The redirect keeps returning after you clean it.
- You can see the redirect but cannot find the code that causes it.
- The site is an online store, or customers have reported a fake payment or verification page.
- Google shows a red warning or “This site may be hacked” next to your site.
Codiffy cleans hacked WordPress and WooCommerce sites 24/7, from $200, usually $200 to $400. If the malware returns, we clean it again free. Call +1 (347) 474-0387 or email haroon@codiffy.com. See the malware removal service
Frequently asked questions
Why does my WordPress site redirect only on my phone?
The hacker’s code checks the device and only redirects mobile visitors. Test with a phone on mobile data, or use the curl command in Step 2 with a phone user agent.
Why is my site redirecting only from Google?
The code checks the referrer and redirects only people who came from a search result. It also helps the hacker avoid being noticed by the owner, who usually types the address directly.
Can a redirect hack happen with no malware in my files?
Yes. If the siteurl or home setting in the database was changed, or a script was injected into your posts or widgets, the files can look clean. Always check the database.
Will Google flag my site for a redirect hack?
It may label your results as hacked. Clean the site first, then follow our guide on the “This site may be hacked” warning.
About the author
Muhammad Haroon Ur Rasheed founded Codiffy in 2019. He has been a full-time WordPress and back-end developer since 2012 and has fixed broken, slow and hacked WordPress and WooCommerce sites for businesses across the United States and Canada. Codiffy works from Rawalpindi, Pakistan, in US and Canadian business hours.

