Web

Website Redirecting to Spam Sites? How to Find and Remove Redirect Malware

Talha Aslan 17 min read

Short answer

Website redirecting to spam: what should you do right now?

A website redirecting to spam means malicious code added to your site without permission is sending some visitors to gambling, adult, or scam pages. The code usually hides in a server rule, injected JavaScript, the database, or a cron job. Your first moves are to take a backup and change every password.

Keep reading for the full details and examples

To keep the order straight while under pressure, work through this short list first, then use the sections below to find where the malware lives:

  1. Take a full backup of the current site, but do not treat it as clean. Keep it only for investigation.
  2. From a clean device, change the passwords for your hosting panel, FTP, database, and admin panel.
  3. Note any admin accounts you do not recognize, then remove them.
  4. Check the Security Issues report in Google Search Console.
  5. Tell your hosting provider; most hosts can run an extra scan on the server side.

This article covers only redirect malware. For the broader roadmap after an attack, read our guide my business website got hacked: the first 24 hours.

Why does redirect malware only affect some visitors?

Because the attacker wants to stay hidden. Google's spam policies state plainly that injected redirects can depend on the referrer, user agent, or device. In Google's own example, a URL clicked from search results may redirect, while the same URL typed directly into the browser may not.

As a result, site owners open their site every day and see nothing wrong. Meanwhile, a customer coming from Google lands on a stranger's page. The malware may also check other conditions:

  • Device type: it redirects only phone visitors, so desktop looks clean.
  • Login status: users logged into the admin panel never see the redirect.
  • First visit: once someone gets redirected, a cookie may show them the normal site for a while.
  • Time and country: some code fires only at certain hours or for visitors from certain countries.

These conditions can also stack; for example, only first-time phone visitors arriving from search results get redirected. In short, "it works for me" proves nothing. You need a test method built around these conditions.

How do you confirm your website redirecting to spam?

When you have a website redirecting to spam, the goal of confirmation is to find the exact trigger. If you start searching files before that, you will have no way to test whether your fix worked.

  1. Open a private window, stay logged out, search for your site on Google, and click the result.
  2. Repeat the test on a phone using mobile data instead of Wi-Fi.
  3. Open the Network tab in developer tools and enable the option to preserve the log. That way you can see each step of the redirect chain.
  4. If the chain shows a 301 or 302 status, the redirect is probably server side. If the page first loads with a 200 and then jumps elsewhere, the source is usually JavaScript.
  5. Check the server's first response separately with a redirect checker.

For the last step, you can use our redirect checker: enter your URL and look for any address in the chain that is not your own domain. However, JavaScript redirects run in the browser and will not show in the server response, so do not skip the browser test.

Where is the malware likely hiding, based on the symptom?

The table below is a starting map based on our field experience, not a fixed rule. A single site can have more than one hiding place at the same time.

SymptomLikely hiding placeFirst check
301 or 302 in the Network tab, page never loads.htaccess or server configurationRead every .htaccess file in the root and subfolders
Page loads, then jumps to another site after a few secondsTheme, plugin, or injected JavaScriptSearch the source for external domains you do not know
Redirect only when arriving from GoogleServer rule or PHP code that checks the referrerLook for rules that mention search engine names
Redirect only on phonesRule or code that checks the user agentLook for conditions with mobile device names
Cleaned file returns the next dayCron job, backdoor file, or another site on the accountReview cron jobs and other sites on the same hosting account
Files look clean but the redirect continuesContent, settings, or widget records in the databaseSearch the database for external domains and obfuscated code
Thousands of unknown URLs in Search ConsoleSpam pages generated on your serverLook for new URL patterns in the page indexing report

The last row calls for a separate cleanup. Our article on unknown spam URLs in Search Console explains the difference between 404 and 410 in that case.

How do you spot a malicious redirect rule in .htaccess?

On Apache and LiteSpeed servers, the .htaccess file can redirect requests before a page even loads. Attackers love this file, because one line affects the whole site and most owners never open it.

In practice, suspicious rules share common traits. For example, a condition that looks for a search engine name in the referrer, a condition that looks for mobile device names in the user agent, and then a redirect to a domain that is not yours. In addition, lines hidden at the very top or below hundreds of blank lines are a common trick.

  • Open the .htaccess file in the root folder and scroll all the way to the end.
  • Also check .htaccess files in subfolders such as the uploads folder; malware sometimes sits only there.
  • Find the default .htaccess content for your content management system in its official documentation and compare.
  • Before you delete an unfamiliar line, copy the file into an investigation folder.

On the other hand, not every redirect rule is malicious. HTTPS and www redirects are normal, and we show their correct form in how to check an HTTP to HTTPS redirect.

How do you find injected JavaScript?

If the page opens and then moves to another site, the source is most likely code running in the browser. Google's spam policies also describe code injection as malicious JavaScript added directly to the site or inside iframes.

So, to find it, do not rely on the browser's view source option alone. Use the Sources and Network tabs in developer tools instead, because malicious code sometimes arrives later from another file and never appears in the initial source.

  • In the Network tab, list every JavaScript request that does not come from your domain, your CDN, or services you know.
  • Watch for very long single-line code full of meaningless character strings; attackers often hide code with encodings such as base64.
  • Search your theme header and footer templates for code blocks you did not add.
  • If you use a tag manager, check its tags too, since a compromised account can inject code from there.

These scripts often come from domains that look like yours but differ by a letter or two. So instead of skimming the list, read each domain letter by letter; resemblance is an attacker's favorite camouflage.

Finding the code is not the end. If you do not discover who placed it there and through which hole, it will come back within days.

How do you search the database for hidden malware?

If the redirect continues after you clean the files, the malware is likely in the database. Content management systems store post content, widgets, theme settings, and the site address there. Therefore, an attacker can add code or an external URL to one of these fields and make it run on every page.

For instance, you can search with a database management tool or in a text copy of your backup. Look for URLs that are not your domain, iframe tags, and long meaningless strings. On WordPress sites, also confirm that the site address and home address settings truly point to your own domain.

Be careful at this stage. Random bulk replacement in the database can break serialized settings and take the whole site down. So find first, take notes, and then clean entries one at a time. For a step by step WordPress cleanup, see our guide WordPress site hacked: what to do first.

Why do cron jobs bring the malware back?

Cron jobs run a command automatically at set intervals. Attackers use them as insurance: you delete the malware, and overnight a cron job downloads or rewrites it. That is how the "I cleaned it, and it started again the next day" loop begins.

First, open the cron section in your hosting panel and read every job one by one. You will recognize backup jobs or jobs from your content management system that you set up yourself. However, treat any job that downloads files from an external address, runs a file you do not recognize, or calls a script with a meaningless name as suspicious.

Also check these places:

  • Other sites on the same hosting account. Malware on one site can reinfect another site on the same account.
  • Executable files inside the uploads folder. An image folder should not contain code files.
  • Core files with unusual last modified dates.

Backdoor files often carry innocent-looking names, such as a file that resembles a core file but sits in the wrong folder. That is why you should use the file list from your system's official release as the baseline and question every file that is not on it.

In short, cleanup is not finished until you close both the backdoor and the mechanism that brings it back.

What does the Search Console Security Issues report tell you?

Google's official Security Issues report documentation says the report shows Google's findings when your site is hacked or could harm visitors. If there are no issues, you see a green check mark. Affected pages may also show a warning label in search results or an interstitial warning in the browser.

According to the documentation, the report separates hacked content issues such as malware, code injection, content injection, and URL injection. It also lists sample affected URLs for each issue. These samples are valuable for diagnosis, because they show on which page and under which condition Google saw the malware.

Still, one important note: an empty report does not mean your site is clean. Google does not detect every infection right away, and code that only fires for some visitors may never appear there. If you have not connected Search Console yet, do it now with our Search Console beginner's guide, because verifying the property is a prerequisite for seeing this report.

How do you request a review from Google after cleanup?

If the Security Issues report lists a problem, you send a review request from the report once the cleanup is done. Google's documentation describes a clear sequence, and following it matters.

  1. Expand each issue and follow the steps behind its learn more link.
  2. Check the sample URLs, but fix the issue across the whole site, not only on those pages. The documentation states that fixing the issue on just some pages will not earn a partial return to search results.
  3. Fix every listed issue and test your fixes.
  4. Once every issue is fixed on every page, use the request review option in the report.
  5. In the request, explain exactly what the issue was, which steps you took, and what the outcome was.

According to the documentation, reviews can take days to weeks, and you should not resubmit while a request is still pending. The official page gives no exact timeframe, so check the current wording there. Also, nobody, including us, can guarantee the outcome; Google makes the decision.

How does redirect malware usually get into a site?

A cleanup that ignores the entry point stays half done. In our field experience, the most common entry points fall into a few groups, and most of them are within the owner's control.

  • Outdated plugins and themes: an old version with a known vulnerability is an easy target for automated bots.
  • Pirated or unknown-source themes and plugins: "nulled" copies shared for free often ship with a backdoor built in.
  • Stolen or guessed passwords: reusing one password in several places spreads a single leak to all of your sites.
  • Access left for former staff and agencies: FTP or admin accounts that nobody closed stay open for years.
  • Abandoned sites on the same account: a forgotten test site opens a path to your main site.

So after cleanup, always ask which door the attacker used. Server access logs showing requests to the uploads folder and unfamiliar login attempts give you clues. If you cannot access the logs, ask your host. Even if you never find the exact door, closing everything on this list reduces the risk considerably.

What should you tell a customer who reports the redirect?

A customer complaint about a website redirecting to spam is often the first signal, so do not brush it off. Thank them first, then ask which device, which link, and what time they used. That information speeds up finding the trigger.

Then give a calm, honest explanation. For example, a short message such as "we found an unauthorized redirect on our site, we are cleaning it now, and we ask you not to enter personal information on the site in the meantime" protects trust. Do not promise details about the attack, the culprit, or an exact time it will be fixed.

If your site has forms, payments, or member accounts, the situation is more sensitive. In that case, review whether personal data was affected and ask a lawyer whether you have any legal notification duties. This article is not legal advice.

Which evidence should you keep during cleanup?

Specifically, keeping evidence matters both for finding the cause and for showing what happened if a dispute comes up later. Saving before deleting is the most skipped step in any cleanup.

  1. Record a screen capture of the redirect and save the chain from the Network tab.
  2. Keep copies of suspicious files outside the site, in a folder where they cannot run.
  3. Note the files' last modified dates; they help you estimate when the attacker got in.
  4. Ask for copies of the server access and error logs for those days.
  5. Take screenshots of the sample URLs in Search Console.

In addition, tidy records shorten the diagnosis considerably if you decide to work with a specialist. The specialist does not start from scratch but goes straight to the cause using the traces you collected.

What can you ask your hosting provider for?

We are not a hosting company and do not run servers, but your host plays an important role here. Most hosts take malware seriously, since on shared servers it can affect other customers too.

Above all, be specific in your support ticket. For example, you can ask for a server-side malware scan, access logs for recent days, a list of the cron jobs running on your account, and any older server-level backups. Check your host's own pages for which services they offer and whether they cost extra.

That said, a host's scan does not catch everything. Code hidden in the database or a tag added to your tag manager may not show up in a server scan. So even if your host says the account is clean, repeat your own browser tests.

How do you decide between cleaning it yourself and getting help?

To be honest, a careful site owner can clean up simple cases where the malware sits in a single .htaccess line. However, when the problem hides in several places or keeps coming back after cleanup, trial and error wastes time and hurts your search visibility.

Seriously consider getting help if any of these apply: the malware returns after cleanup, the site has old plugins and custom code nobody documented, there are several sites on the same account, or the site has no backup.

What we contribute is not a cleanup service but a clean, sustainable foundation. As Talha Aslan and team, our web design services build sites with lean, documented code that others can take over, instead of bloated themes and plugin stacks, and we deliver them with Search Console connected. Rebuilding an old site is often a safer start than patching it forever.

Example scenario: only phone visitors from Google get redirected

This is an example scenario, not a real client case. A service business owner gets messages from customers saying "we got sent to another site when we opened yours." Yet every time the owner opens the site, everything looks normal.

  1. The team reproduces the issue in a private window and on a phone with mobile data by clicking from Google; direct visits on desktop show no problem.
  2. The Network tab shows the first response is a 302, so the redirect is server side.
  3. Below hundreds of blank lines in the root .htaccess file, they find a rule with search engine and mobile device conditions.
  4. After they delete the rule, it returns the next day, so the team checks the cron jobs and finds one that downloads a file from an external address.
  5. Finally, they remove the job, the backdoor file, and an outdated plugin, change every password, and request a review in Search Console.

The team's first step matters too: it reproduces the problem on its own device before touching any file. As a result, it can rerun the same test after cleanup and prove the issue is truly gone.

The lesson is simple. Deleting the visible rule removes the symptom but not the cause. The lasting fix is to find the entry point and the mechanism that brings the malware back, together.

What are the most common mistakes with a website redirecting to spam?

In our experience, the mistakes that drag out a cleanup are always similar. Avoiding them helps you solve the problem once and for good.

  • Testing only in your own browser: as a logged-in admin, you never see the redirect.
  • Restoring an infected backup: if you do not know when the malware got in, the restored backup brings it back.
  • Not changing passwords before cleanup: if the attacker is still inside, they get back in during the cleanup.
  • Deleting only the visible file: the backdoor and the cron job stay in place.
  • Skipping updates: without closing the hole, cleanup stays temporary.
  • Giving access to strangers who promise a "quick cleanup" for money: handing your panel password to someone you cannot verify creates a new risk.

We cover the general framework of common web vulnerabilities in our article on the OWASP Top 10.

How does redirect malware affect your search rankings?

Google's spam policies define redirects meant to deceive users as sneaky redirects. As an example, they describe showing desktop users a normal page while sending mobile users to a completely different spam domain. Even if you did not do this yourself, malware on your site produces exactly that behavior.

Consequently, the impact shows up on three levels. First, visitors lose trust and do not come back. Second, Google may show your pages with a warning label, or the browser may display a warning screen. Third, spam pages generated on your server pollute your indexing reports. Nobody can say exactly how long recovery takes; the official documentation does not specify it.

For spam policies and recovery, see our article on Google spam updates and how to protect your site. To make sure all your remaining redirects are healthy, our guide to fixing redirect chains also helps.

How do you keep your site from getting reinfected?

In other words, the real work starts after cleanup. The checklist below is not a one-time task but a regular maintenance habit.

  1. Keep your content management system, theme, and every plugin updated, and fully delete the ones you do not use.
  2. Use a separate strong password for each panel and turn on two-step verification wherever possible.
  3. Create personal admin accounts, avoid shared logins, and close access as soon as someone leaves.
  4. Keep regular backups stored outside the site, and test that you can actually restore them.
  5. Keep Search Console email notifications turned on.
  6. Once a month, test your site in a private window and on a phone by clicking from Google.

To create strong, unique passwords, you can use our password generator. We explain how to plan backups in our website backup strategy guide.

When does it make sense to rebuild the site?

On some sites, a website redirecting to spam turns cleanup into a dead end: a theme nobody has updated in years, plugins whose developers stopped supporting them, and custom code nobody can explain. In a setup like that, a new hole opens after every cleanup.

The scope of our web design work is clear: information architecture and user experience, brand-specific design, lean custom code instead of bloated themes and plugin stacks, SEO foundations including a Search Console connection, an admin panel you can edit yourself, and documented code others can take over. We do not offer a security guarantee; we say that a clean, easy to maintain foundation lowers the risk.

If you want to move your site onto solid ground from the start, you can review the process and scope on our corporate website design page and describe your needs in the quote section. We confirm scope and timeline in writing after your request.

Frequently Asked Questions

Why does my website redirect only on mobile?
Because the malicious code checks the user agent and targets only mobile devices. Google's spam policies note that injected redirects can depend on the device, user agent, or referrer. That is why a site that looks clean on desktop sends phone users elsewhere. Test on a phone with mobile data, in a private tab, by clicking from Google.
There is no redirect on my computer, so is my site clean?
No, that alone does not prove it. Malware often skips logged-in admins, people who type the URL directly, and visitors who were already redirected once. Test in a private window, logged out, on a different device, and by clicking a Google result. Save the redirect chain from the Network tab as evidence while you test.
I deleted the malware but it came back the next day. Why?
Most likely a cron job or backdoor file is rewriting it. Read every cron job in your hosting panel, check the uploads folder for code files, and review other sites on the same account. To close the hole for good, also update your plugins and themes and change every password from a clean device.
If the Security Issues report is empty, does that mean no problem?
No, malware can exist even when the report is empty. Google does not detect every infection right away, and code that only fires for some visitors may never appear there. When the report does list issues, the sample URLs are very helpful for diagnosis. Check it regularly and keep your own tests going.
How long does a Google security review take?
Google's documentation says reviews can take days to weeks and does not give an exact timeframe. Do not resubmit while a request is pending. In your request, explain the issue, the steps you took, and the outcome. You also need to fix the problem across the whole site, because a partial fix does not earn a partial return.
Is restoring an older backup enough to fix the infection?
Not on its own. If you do not know when the malware got in, the backup may be infected too. Even with a backup you know is clean, the attacker can return the same way unless you close the hole. After restoring, apply updates, change every password, and remove any accounts you do not recognize.
  • website redirecting to spam
  • redirect malware
  • hacked website
  • htaccess
  • Search Console security issues
  • sneaky redirects
  • website security
Share:
Talha Aslan

Google Partner digital marketing expert. Hands-on with SEO, Google Ads, web design and e-commerce projects since 2012; every post here comes from that experience.

Next project

Get a quote for your project.

Your brief goes straight to Talha Aslan and team: strategy led by Talha, delivery by an experienced team. We reply the same day and send the scope, timeline and price as a written quote within 1 business day.