How I fixed ~338 Google Search Console 404 errors from removed language URLs on a multilingual WordPress site
A multilingual SaaS website kept getting hundreds of “Not found (404)” errors in Google Search Console for languages it no longer offered. I traced the cause, then shipped a 134-line WordPress must-use plugin that sends each dead URL to the right place. No live page was affected.
- 404s Fixed
- ~338 URLs in Search Console
- Retired Prefixes
- ~26 Languages Handled
- Production Test
- 30 / 30 Sample URLs Correct
- Regressions
- 0 Live Pages Changed (145 Checked)
- Problem: ~338 “Not found (404)” errors in Google Search Console, from about 26 language versions the site no longer offered.
- Root cause: Google re-crawling old URLs from a retired auto-translation system. The live site itself was clean.
- Fix: A small WordPress mu-plugin that runs only on real 404s and sends a 301 redirect to the matching English page.
- Result: Errors cleared, old links recovered, link value kept, and zero live pages affected (175 URLs tested).
01 — CONTEXT
Context: a WordPress site that went from almost 30 languages to 3
The site runs WordPress with Elementor and Polylang. An earlier auto-translation system had created a /xx/ copy of every page in about 26 languages. Each copy had its own hreflang tags and sitemap entries.
The site was later narrowed to the three languages with real, reviewed translations: English, Spanish and Chinese. The extra language copies were removed. Google, however, still had those URLs in its index and kept coming back to crawl them.
02 — THE PROBLEM
The problem: hundreds of 404 errors in Google Search Console
Search Console’s Pages report showed roughly 338 URLs as “Not found (404)”. Almost all of them had a retired language prefix:
This caused three real problems:
Googlebot kept spending requests on pages that no longer existed.
Old backlinks and bookmarks led to an error page, even though the same content existed in English.
Real problems were buried under hundreds of stale errors.
03 — INVESTIGATION
Finding the root cause of the 404 errors
Before writing any code I checked whether a recent change had caused the errors:
Only en, es, zh and x-default. No dead languages were advertised.
No /xx/ entries for retired languages.
No language-switcher widget linking to the old languages.
Every live URL returned 200.
One detail shaped the whole solution. When I checked a sample of 22 dead slugs, every one still had an English equivalent. The content existed; only the language prefix was dead.
04 — OPTIONS CONSIDERED
301 redirect vs 410 Gone vs homepage redirect: choosing the right fix
| Approach | Why it was / wasn’t chosen | Verdict |
|---|---|---|
| Manual redirect rules | Hundreds of rules to write and maintain by hand, and they would miss URLs Google hasn’t reported yet. | Rejected |
Return 410 Gone everywhere | The page would still be lost to visitors even when an English version exists. The client also wanted /fr/xyz to behave exactly like /xyz. | Rejected |
| Send every dead URL to the homepage | Google treats this as a soft 404, so it hurts rankings rather than helping. | Rejected |
| Rule-based fallback, only on real 404s | Covers every dead URL now and in the future. Sends visitors to the matching English page, and leaves true orphans as normal 404s. Live pages can’t be affected. | Chosen |
05 — THE SOLUTION
The solution: a WordPress mu-plugin that redirects only real 404s
I built it as a WordPress must-use plugin (dead-lang-fallback.php). It loads on every request, can’t be switched off by mistake in wp-admin, and is kept in version control. It hooks into template_redirect at priority 99, so it runs after the site’s existing multilingual fallback has done its work.
- 1 · Did WordPress already return a 404?If not, stop immediately. Every live page skips this code completely, which is what makes the change safe.
- 2 · Is the first part of the URL a dead language?It must be two lowercase letters and not a language registered in Polylang. The live list is read from Polylang at runtime, so a language added later is protected automatically.
/es/… /zh/… → ignored · /fr/… /tr/… → continue - 3 · Language root only? → 301 to the homepageA bare section root like
/fr/is the one deliberate homepage redirect. It is a low soft-404 risk. - 4 · English version exists? → 301 to itIt looks up a published page by its path, or a blog post by its final slug, and redirects to the canonical URL. Visitors get the real content, and Google moves the old URL’s signals to the live page.
/pl/pricing/ → /pricing/ - 5 · Exists nowhere? → leave the normal 404No 410 and no homepage bounce:
/fr/xyzbehaves exactly like/xyz, and Google drops it naturally.
// HARD GATE: only act on a request WordPress already resolved to a 404.
if ( is_admin() || ! is_404() ) return;
$lang = strtok( $path, '/' );
if ( ! preg_match( '/^[a-z]{2}$/', $lang ) ) return;
if ( in_array( $lang, pll_languages_list( [ 'fields' => 'slug' ] ), true ) ) return;
$rest = trim( substr( $path, strlen( $lang ) ), '/' );
if ( $rest === '' ) { wp_safe_redirect( home_url( '/' ), 301 ); exit; }
$target = dlf_resolve_target( $rest ); // published page or post → canonical URL
if ( $target ) { wp_safe_redirect( $target, 301 ); exit; }
// else: do nothing — WordPress keeps its normal 404.
Built-in safety
- No open redirects: Targets are always internal permalinks taken from real published posts and pages, sent with
wp_safe_redirect. - No loops or chains: Every redirect is a single hop to a
200page. - Drafts, trashed and private content are never used as targets.
06 — TESTING & ROLLOUT
Testing and rollout on staging and production
All 145 setup-guide sitemap URLs (5 guides across ~25 languages, plus es and zh) still returned 200 with the plugin active. These are real pages that share prefixes like /fr/, so they were the riskiest case.
All 30 sample URLs from Search Console behaved as designed. Language ghosts redirected in one hop, real non-existent slugs stayed 404, /fr/setup-guide/ stayed 200, and /es/ and /zh/ were untouched.
A few /upload/*.m3u8 404s, from expired video streams, were excluded in robots.txt. I first confirmed that site images live under /wp-content/uploads/, so they were unaffected.
07 — RESULTS
Results: 404 errors cleared, visitors recovered, nothing broken
Dead language URLs move from “Not found (404)” to “Page with redirect”, and the fix was submitted for validation.
Old links and bookmarks now land on the matching English page instead of an error.
301s pass the old URLs’ signals to live canonical pages instead of dropping them.
The 404-only gate means no live page can be affected. 145 + 30 URL checks back this up.
Dead URLs Google hasn’t reported yet are handled automatically, with no list of rules to maintain.
134 lines in one version-controlled file. Plugin and theme updates can’t overwrite it.
08 — WHAT I LEARNED
Lessons learned for fixing 404 errors after removing languages
1 Find out why before you fix
Showing that the site was clean turned an urgent-looking bug into a predictable crawl backlog, and pointed to a fix at request time instead of rebuilding pages.
2 A strict gate is the best safety feature
Acting only on requests that are already 404s made the change provably harmless to every working page.
3 Redirect to an equivalent, never to the homepage by default
Mass homepage redirects create soft 404s. A page-to-page 301 keeps both the visitor and the ranking signals.
4 The simplest solution was the right one
The first draft used 410 responses. Matching the client’s rule (“/fr/xyz should act like /xyz”) removed a whole branch of logic and made the behaviour easier to explain.
09 — FREQUENTLY ASKED QUESTIONS
Frequently asked questions about 404 errors and old language URLs
Why does Google Search Console show 404 errors for pages I deleted long ago?
Google keeps old URLs in its index and re-crawls them for months. If a site once had language versions such as /fr/ or /pl/ and later removed them, Search Console reports each old URL as “Not found (404)” until it gets a redirect or drops the URL.
Should removed language pages return 404, 410 or a 301 redirect?
If the same content still exists in another language, a 301 redirect to that page is best: visitors land on real content and ranking signals move to the live URL. If nothing equivalent exists, a normal 404 is fine and Google drops it on its own.
Is it bad for SEO to redirect all 404 pages to the homepage?
Yes. Google treats mass redirects to the homepage as soft 404s, so they give no SEO benefit and can confuse users. Redirect each URL to its closest equivalent page, or let it return 404.
How do I redirect old language URLs in WordPress without manual redirect rules?
Hook into template_redirect, act only when WordPress has already returned a 404, check that the first path segment is a language code that is no longer active, look up the matching English page or post, and send a single 301 redirect to its permalink.
Will a 404 redirect fallback affect my live pages?
Not if it is gated on is_404(). The code only runs for requests WordPress could not resolve, so every working page returns 200 exactly as before.
TECHNOLOGY STACK
Planning a 404 Clean-up or International SEO Audit?
We audit and fix Google Search Console crawl errors, legacy URL structures, and multilingual routing without risking live traffic or rankings.
Discuss your project