Phantom pages in Search Console: return 410, not a redirect

· 4 min read

I was looking through Search Console for a content site I work on and noticed a cluster of URLs that made no sense: paths like /articles/placeholder/embed/ with a pile of query parameters appended. None of them were routes I had ever written. All of them were returning—effectively—nothing. And Googlebot was revisiting them over and over.

Here's what happened, and how a single middleware rule fixed it.

How the phantom URLs got created

The site uses a CMS where editors can add an Instagram video to an article. For a batch of AI-generated content, that field was never filled in—it held a placeholder string rather than a real https://www.instagram.com/... URL.

The frontend was dropping that value straight into the embed markup without checking it first:

// Before the fix — no validation
<blockquote
  className="instagram-media"
  data-instgrm-permalink={article.videoUrl}
/>

Instagram's embed.js reads every data-instgrm-permalink on the page, appends /embed/?cr=1&v=14&wp=<width>&rd=<origin>&rp=<path> to it, and loads the result in a hidden iframe. When videoUrl is a full https://www.instagram.com/p/ABC/ URL, the iframe loads from Instagram's servers and nobody on our domain ever sees it.

But when videoUrl is a short string that isn't a URL—say "placeholder"—the browser resolves it as a relative path against the current page. A page at /articles/my-article ends up requesting /articles/placeholder/embed/?cr=1&... from the same domain. That request hits our server.

Googlebot runs JavaScript. It found those iframe src values and queued them for crawling. At the time, the site's catch-all handler redirected every unknown path to the homepage. Google reads a redirect-to-homepage as a soft 404: "there might be content here, I should check back." So it did, repeatedly.

Fix part one: validate before you build the embed

The first step is stopping new phantom URLs from being created. Only build the embed markup when the field value is actually a valid URL pointing at the right host:

function resolveInstagramUrl(raw: string | null | undefined): string | null {
  if (!raw) return null;
  try {
    const url = new URL(raw);
    if (url.hostname !== 'www.instagram.com') return null;
    if (!/^\/(p|reel|tv)\//.test(url.pathname)) return null;
    return raw;
  } catch {
    return null;
  }
}

Then use it in the component:

const embedUrl = resolveInstagramUrl(article.videoUrl);

return embedUrl ? (
  <blockquote className="instagram-media" data-instgrm-permalink={embedUrl} />
) : null;

No valid URL, no blockquote, no iframe, no phantom path. That prevents the problem going forward. But Google had already crawled a large number of old URLs and would keep recrawling them until something told it to stop.

Fix part two: return 410 in the middleware

The pattern for these paths is predictable: they all match /articles/<slug>/embed or /articles/<slug>/embed/. No real page in the app ever ends in /embed. That makes it safe to intercept the whole pattern at the edge and return a 410.

In a Next.js middleware (or any proxy layer sitting in front of the app):

import { NextRequest, NextResponse } from 'next/server';

const PHANTOM_EMBED = /^\/articles\/[^/]+\/embed\/?$/;

export function middleware(request: NextRequest) {
  const { pathname } = request.nextUrl;

  if (PHANTOM_EMBED.test(pathname)) {
    return new NextResponse('Gone', {
      status: 410,
      headers: {
        'Content-Type': 'text/plain; charset=utf-8',
        'X-Robots-Tag': 'noindex',
      },
    });
  }

  // rest of the middleware...
}

This runs before any auth logic or page rendering, so the response is as cheap as possible.

Why 410 and not 404

Both signal "nothing here," but they carry different weight.

A 404 means "not found right now." Google may keep the URL in its index and retry it for weeks before deciding it's permanently gone.

A 410 means "gone, and not coming back." Google drops 410s from the index faster. For URLs that were never real pages and never will be, 410 is the honest answer.

The robots.txt trap

My first instinct was to block the pattern in robots.txt. Don't do that here. If Google can't crawl those URLs, it never receives the 410. The URLs stay in Search Console in a "blocked by robots.txt" state rather than getting deindexed. The whole point is to let Google crawl the URL one more time, see the 410, and drop it. After deploying the middleware, I went into Search Console and clicked Validate Fix to speed that process along.

What I'd do differently next time

Validate at the data layer. The CMS accepted the placeholder value without complaining. A schema-level check—or even a simple field validator—would have made this impossible to publish. The embed code never should have needed to handle a bad value.

Don't redirect 404s to the homepage site-wide. The soft-404 problem here was amplified by the catch-all redirect. A proper 404 response from the not-found handler would have told Google much sooner that these URLs were meaningless. I left that change out of scope here because it touches the whole site, but it's on the list.

Check Search Console for iframe src patterns. I wouldn't have found this by looking at page source. It only showed up in Search Console's coverage report—URLs that looked like query-string noise until I read the rp= parameter and traced it back to the embed script. It's worth scanning Search Console periodically for URL shapes you don't recognise.

  • #seo
  • #nextjs
  • #typescript
  • #search-console
  • #googlebot

Written by Ryan Yovanda