Design a multi-language routing without cloaking or automatic redirects issues.
- User
Design a multi-language routing without cloaking or automatic redirects issues.
Assistant
Design a multi-language routing without cloaking or automatic redirects issues.
The user wants to know how to design a multi-language website routing strategy that avoids "cloaking" (showing different content to search engines than users) and problematic "automatic redirects" (redirecting users based on their IP or browser settings without a choice).
I need to explain the best practices for international SEO (iSEO) and user experience (UX) regarding URL structures, hreflang tags, and navigation.
Key Concepts to Cover:
/en/about -> /fr/about), don't dump them on the homepage.Structuring the Answer:
example.com/en/) for most use cases.Refining the "Cloaking" and "Redirect" nuances:
/en/, you might hide your /fr/ content from the crawler, or confuse it. Also, it annoys users (e.g., an English speaker traveling to France wants the English site, not forced into the French one).Drafting the Content:
domain.com/lang/. It's the safest.domain.com should probably default to one language (usually English) or act as a selector page, but avoid redirect loops.rel="alternate" hreflang="x". Explain that this tells Google "I have this page in Spanish too."Detailed Implementation Plan (Mental Draft):
/en, /fr)./fr/./fr/.Self-Correction/Refinement: The user asked specifically about "without cloaking or automatic redirects." So, I must emphasize:
Code Examples:
Provide a snippet for the HTML <head> and maybe a React/Next.js routing example since that's popular.
Let's structure the response logically:
This looks solid. I will write the response following this structure. Designing a multi-language architecture requires balancing three competing interests: User Experience (UX), Search Engine Optimization (SEO), and Maintainability.
To avoid Cloaking (showing different content to Googlebot than users) and Automatic Redirects (forcing users to a specific language based on their IP or browser settings without their consent), you must rely on explicit user choice and clean URL structures.
Here is the definitive guide to designing this routing system.
The foundation of avoiding cloaking is ensuring that every piece of content has a unique, crawlable URL. Do not rely on cookies or sessions to determine language for search engines.
The industry standard is Subdirectories (e.g., domain.com/en/, domain.com/fr/). This consolidates your domain authority while keeping languages distinct.
The Hierarchy:
/): Should usually be a "Language Selector" page or default to your primary market language (e.g., English)./en, /fr, /es): Contain the specific localized content.To avoid the "automatic redirect" issue (which causes problems like a US traveler in Spain being stuck on the Spanish site), you must implement a Root Landing Page strategy rather than an IP Auto-Redirect strategy.
domain.com:
navigator.language) and highlight the suggested language (e.g., "Go to French Version"), but do not force the redirect.domain.com/fr.pref_lang=fr.domain.com later:
pref_lang exists, soft redirect (or provide a bypass link) to that language.Why this avoids Cloaking: Googlebot usually crawls from US IPs. If you auto-redirect based on IP, Googlebot will only ever see the US version of your site. By using a Gateway page, Googlebot sees the links to all language versions, ensuring your /fr/ and /es/ pages get indexed.
To tell Google that /fr/about is the French version of /en/about, you must use hreflang tags. This prevents "duplicate content" penalties and ensures the right language appears in the right regional search results.
In the <head> of every page:
<!-- On the English About Page (/en/about) -->
<link rel="canonical" href="https://example.com/en/about" />
<link rel="alternate" hreflang="en" href="https://example.com/en/about" />
<link rel="alternate" hreflang="fr" href="https://example.com/fr/a-propos" />
<link rel="alternate" hreflang="x-default" href="https://example.com/en/about" />
x-default: This is required. It tells Google which version to show users if their language doesn't match any of your specific targets (e.g., a Japanese user visiting your site). Usually, this points to the English version or the Root Gateway page.Since you aren't forcing redirects, you must provide a manual switcher. This should be visible in the header or footer.
UX Requirements:
/en/products, they should be directed to /fr/produits, not the French homepage. This requires mapping routes in your application logic.Here is a conceptual implementation using a file-based router (like Next.js) that avoids automatic redirection.
Middleware Logic (Conceptual):
// middleware.js (Logic for handling root path)
export function middleware(request) {
const url = request.nextUrl;
const pathname = url.pathname;
// 1. If already in a language subfolder, serve the page normally.
if (pathname.startsWith('/en') || pathname.startsWith('/fr')) {
return NextResponse.next();
}
// 2. Check for a SAVED PREFERENCE (Cookie)
const prefLang = request.cookies.get('user_lang');
// ONLY redirect if user has explicitly chosen a language before
if (prefLang) {
url.pathname = `/${prefLang}${pathname}`;
return NextResponse.redirect(url);
}
// 3. NO PREFERENCE & NO LANGUAGE IN URL?
// DO NOT redirect based on IP or Headers.
// Instead, rewrite to a "Language Selector" page at the root.
// This ensures Googlebot sees the links, not a redirect loop.
if (pathname === '/') {
// Serve the "Choose Language" page
return NextResponse.rewrite(new URL('/language-selector', request.url));
}
// Fallback
return NextResponse.next();
}
| Feature | Implementation | Risk Avoided |
|---|---|---|
| URLs | domain.com/lang/page | Cloaking: Ensures Google can crawl every version distinctively. |
| Entry Point | Gateway Page at Root | Auto-Redirects: Googlebot (mostly US-based) can discover your FR/ES pages instead of being stuck in the US view. |
| Detection | Manual Selection only | Bad UX: Travelers or VPN users aren't forced into the wrong language. |
| Indexing | hreflang + Sitemaps | Duplicate Content: Google knows which version to serve to which audience. |
domain.com display a page allowing access to all languages?domain.com/fr/ return a 200 OK status (not a redirect)?hreflang tags pointing to all other language versions?