Security

Remove Spam URLs From Google: See What Googlebot Sees First

By , Lead SEO & Co-founder 8 min read
A dim archive room at night where spam-filled trays are being pulled from a shelf into a crimson-lit disposal bin, a cyan scanning beam checking each slot, clean shelves glowing behind and a laptop on a cart

If you want to remove spam URLs from Google after a hack, start by looking at them the way Googlebot does. The page your browser shows you may not be the page Google indexed, and every removal step after this depends on knowing which one is real.

Owners skip that check all the time. They visit a spam URL, see a 404 or their normal homepage, assume it's gone, and wonder why Google still lists it a month later. Usually the spam was still there. It was just being shown to Google and hidden from them.

So this is the order I use: see what Google sees, build the full list, make every spam URL return a "gone" status, clean up Search Console, and only then use the Removals tool and request a review. If you'd rather not do it yourself, you can tell me what's still showing in Google, and I reply with a plan and a fixed quote within one business day.

Step 1: See your site the way Googlebot sees it

Hacked sites often use cloaking (showing one page to search engines and a different one to people). Google's guide to the cloaked keywords hack warns that hackers may serve a fake "page not found" to you while Googlebot still gets the spam.

There are two ways to check. The first is quick and imperfect:

Terminal
# Read-only: fetch a URL as Googlebot claims to, then as a normal browser, and compare.
# Limitation: cloaking that checks Google's real IP addresses won't be fooled by this.
curl -sA "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" https://example.com/suspect-page/ | head -40
curl -sA "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" https://example.com/suspect-page/ | head -40

If the two outputs differ, you've caught the cloaking red-handed. If they match, that proves less than you'd hope, because smarter malware checks where the request really comes from.

The second way is the one that counts. In Search Console, paste the URL into the URL Inspection tool, click Test live URL, then View tested page. You'll see the HTML and HTTP response Google receives right now. Google's own help notes that the default view comes from the last crawl and "is not a live test," so always use the live test after a cleanup.

Run this on a handful of spam URLs before you remove anything. If Google still gets spam, the site isn't clean yet, and removing URLs from the index now is just mopping under a running tap.

Step 2: Build the full list of spam URLs

You can't remove what you haven't found. I pull the list from four places:

  1. Search Console Performance report. Filter by page, sort by impressions, and export. Spam pages that ever showed in search appear here, with their queries.
  2. Search Console Pages report. Look at "Indexed" and the examples under each status. Export what you can.
  3. site:yourdomain.com searches. Add the spam's own words, like a product name or a Japanese word you saw. The results are a sample, not a full count.
  4. The attacker's sitemaps. If they submitted one, it's a ready-made list of what they wanted indexed.

Paste everything into one spreadsheet and look for the pattern. Hack spam almost always has one: a folder name, a file extension, a numbering scheme. You'll need that pattern in step 3.

Step 3: Make every spam URL return 404 or 410

Google's documentation on status codes says that when a previously indexed URL returns a 4xx code, "the indexing pipeline removes the URL from the index." It also says all 4xx codes except 429 are treated the same, so 404 (not found) and 410 (gone for good) both work.

One important limit: this is for pages the attacker created. Real pages that got spam injected into them should be cleaned and kept, not removed.

If your spam URLs follow a pattern, one server rule beats deleting pages one by one. My Japanese keyword hack post has an Apache rule for query-string spam. Here's the Nginx version for a different common pattern, numbered .html pages in a fake folder:

Nginx
# Inside the site's server { } block. Returns 410 Gone for URLs like /goods/48213-cheap-bags.html.
# Could break: any real URL matching the same pattern. Check your real URL list against it first.
location ~ ^/goods/[0-9]+-[a-z0-9-]+\.html$ {
    return 410;
}

That's a regex location block, documented in the Nginx core module docs. Reload Nginx after a config test (nginx -t), then confirm with curl:

Terminal
# Read-only: the spam URL should print 410, a real page 200.
curl -s -o /dev/null -w "%{http_code}\n" https://example.com/goods/48213-cheap-bags.html
curl -s -o /dev/null -w "%{http_code}\n" https://example.com/services/

Two mistakes to avoid here:

  • Don't redirect spam URLs to your homepage. A redirect tells Google the content moved. It didn't. It's gone, and the status code should say so.
  • Don't block spam URLs in robots.txt. Google can't crawl them, so it never sees the 410.

Step 4: Clean up Search Console before you ask for anything

Two things in Search Console can quietly undo your work.

Rogue owners. Under Settings > Users and permissions, look for owners you don't know. Google says an unknown owner means you might have been hacked, and that a removed owner can re-verify as long as their verification token stays on your site. Remove the owner, remove their entry under Unused ownership tokens, and delete the token file or tag from the server.

Spam sitemaps. Open the Sitemaps report and look for sitemaps you didn't submit. Delete the files from the server. Then know this, from the Sitemaps report help: removing a sitemap from the report means Google "won't forget the sitemap or any URLs listed in it." That's fine now, because those URLs return 410. Then submit your own clean sitemap, so Google spends its crawl visits on real pages.

Step 5: Use the Removals tool, but only where it earns its keep

The Removals tool is fast and temporary. According to Google's help page, a successful request "lasts only about six months," and Google can still crawl the page in the meantime. It's a curtain, not a delete button.

Google's cleanup guide draws the same line I do: "Don't use this tool to request removal of any previously good pages that were only damaged by the hacker." So I use it narrowly:

  • Spam URLs that appear when people search your brand name, because those are the ones customers see.
  • A prefix removal for a spam folder, if all the spam lives under one path like /goods/. Double-check that no real page shares that prefix.

The 410 from step 3 is what makes the removal permanent. By the time the six months are up, Google will have recrawled those URLs and dropped them.

Step 6: Request the review last

If your site has a security warning, now's the time. In the Security Issues report, click Request review and describe what you found, what you removed and how the attacker got in. Google's review guide suggests checking your pages with curl or wget first, and confirming Googlebot isn't blocked by robots.txt or noindex.

Going last matters. If you ask before the spam URLs return 410 and the rogue owner is gone, a reviewer can still find problems, and a denied review keeps the warning in place. My post on the "This site may be hacked" warning covers review timelines for each type of warning.

How long until the spam pages are gone?

There's no fixed timeline, and anyone who promises one is guessing. It depends on how often Google recrawls the spam URLs, and spam URLs aren't a priority for Google. The Removals tool hides your most visible ones in the meantime.

Here's what I tell clients. Watch the indexed count in the Pages report over the following weeks. A steady decline means it's working. A flat line or new spam URLs means something is still generating them, and the cleanup isn't finished. That's usually a backdoor, covered in my full WordPress hack cleanup walkthrough.

Vlad's take

The step people skip is the first one. Everything else in this post assumes the site is truly clean from Google's point of view, and the URL Inspection live test is the only way to know that. It takes a minute per URL. Do five. If any of them still shows spam to Google, stop and clean before you touch the index.

Final thoughts

To get spam out of Google: check what Googlebot really sees, list every spam URL, return 410 by pattern, evict rogue owners and their tokens, replace spam sitemaps with a clean one, use the Removals tool for brand searches only, and request the review last. The index recovers on Google's schedule, but in that order, it recovers once.

If you'd like this handled along with the cleanup itself, my hacked site repair service does both. Share what you're seeing and I'll tell you where things stand.

Remove spam URLs from Google FAQs

How do I remove hacked pages from Google quickly?

For speed, use the Removals tool in Search Console on the spam URLs that show up for your brand name. That hides them from search results, but only for about six months. For permanent removal, make every spam URL return a 404 or 410 status, so Google drops them as it recrawls. Doing both is the fastest route that also lasts.

Should I use 404 or 410 to deindex spam pages?

Either one works. Google's documentation says it treats all 4xx status codes except 429 the same way, and drops previously indexed URLs that return them. I prefer 410 for hack spam because it signals a deliberate removal and suits pattern-based server rules. What matters most is that every spam URL returns one, and no real page does.

Why does Google still show spam pages after I cleaned my site?

Usually one of three reasons. Google hasn't recrawled the URLs yet, which can take weeks. The spam is still being served to Googlebot through cloaking, which you can confirm with a URL Inspection live test. Or the spam URLs return a 200 status, often the homepage, instead of a 404 or 410, so Google has no reason to drop them.

Can I use robots.txt to remove spam URLs from Google?

No. Blocking spam URLs in robots.txt stops Google from crawling them, so it never sees that they're gone. Already-indexed URLs can stay in results, sometimes without a description. Google's Removals help page specifically says not to use robots.txt as a blocking method. Let Google crawl the spam URLs and receive a 404 or 410 instead.

Do I need to remove spam pages from Bing too?

It's worth checking. Bing has its own index, and spam that reached Google often reached Bing as well. The 404 and 410 responses work for every search engine, so the server-side fix covers Bing automatically. If you use Bing Webmaster Tools, check it for unknown users and spam sitemaps too, the same way you did in Search Console.

Want a second pair of eyes on your site?

Tell me what's going on in the hacked website repair questionnaire. I reply with a plan and a fixed quote within one business day.

Starting at $350 Start the questionnaire