Create an edge SEO ruleset: header rewrites, path normalization, language detection, and…
- User
Create an edge SEO ruleset: header rewrites, path normalization, language detection, and bot accommodations.
Assistant
Create an edge SEO ruleset: header rewrites, path normalization, language detection, and bot accommodations.
The user wants an "edge SEO ruleset." This implies a configuration meant to be deployed at the "edge" (like a CDN such as Cloudflare, Akamai, Fastly, or VCL) to improve SEO. The specific features requested are:
I need to structure this as a practical guide or a pseudo-code configuration that could be adapted to various platforms. Since Cloudflare (Workers or Page Rules) and VCL (Varnish/Fastly) are the most common contexts for "edge SEO," I will provide examples that feel native to those environments but keep the logic generic enough to be portable.
Structure:
utm_source).X-Robots-Tag (for staging/dev environments).Link: rel="canonical" (set dynamically if needed).Vary: Accept-Language (caching hint).Accept-Language or IP.Content-Language header.Refining the details:
X-Robots-Tag is a powerful edge tool. If a query param is added (like ?debug=true), strip it or add noindex to prevent leakage./us/ if it's trying to crawl /fr/. The rule should be: "If root request and human, redirect. If deep link, serve content."/search?q= from being crawled via X-Robots-Tag: noindex at the edge is cleaner than doing it in HTML.Drafting the Output: I will create a "Master Edge SEO Ruleset" organized by function. I will provide the logic and then a code block for implementation.
X-Robots-Tag injection for specific paths (e.g., /api/, /admin/).Vary: Accept-Language.Content-Language.Let's write the pseudo-code in a format that looks like a mix of VCL and JS so it's universally understood by DevOps/Engineers.
Self-Correction on Bot Accommodation: A common SEO issue is "rendering resources." Sometimes we need to ensure JS/CSS is accessible to Googlebot. An edge rule could explicitly allow Googlebot to access assets that might otherwise be blocked by WAFs.
Let's refine the "Language Detection" part. True SEO best practice is usually not to automatically redirect based on IP (cloaking risk), but to show a banner or use hreflang. However, the prompt asks for "Language Detection," so I will provide the rule but add the SEO warning about IP redirection. I will suggest using Accept-Language header instead of IP for safer SEO implementation.
Final Plan:
Let's generate the response. Here is a comprehensive Edge SEO Ruleset designed for implementation at the Content Delivery Network (CDN) level (e.g., Cloudflare Workers, Akamai Edge Workers, Fastly VCL).
This ruleset focuses on four pillars: Hygiene (Normalization), Globalization (Language), Compliance (Headers), and Crawlability (Bots).
Duplicate content penalties occur when search engines index the same content under multiple URLs (e.g., /about vs. /ABOUT vs. /about/). These rules force a single, canonical structure.
Rule 1: Lowercase Enforcement
Rule 2: Trailing Slash Standardization
.html or .jpg), append a trailing slash. If it is a file, remove the trailing slash.Rule 3: Query Parameter Cleaning
utm_source, gclid, session_id, fbclid).Edge headers instruct browsers and crawlers on how to handle content without modifying the origin server code.
Rule 4: Strict Transport Security (HSTS)
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload.Rule 5: X-Robots-Tag Injection
X-Robots-Tag: noindex, nofollow to prevent accidental indexing of non-production sites.?sort=price), inject X-Robots-Tag: noindex, follow to preserve link juice but remove low-value pages from the index.Rule 6: Canonical Header Link
Link: <https://www.example.com/path/>; rel="canonical".<head>.Handling internationalization at the edge prevents "flash of content" issues and redirects users/crawlers efficiently.
Rule 7: Accept-Language Redirects (Soft Redirects)
Accept-Language header.
fr is preferred AND user is on example.com (root), serve content from /fr/ (rewrite) or 302 Redirect to /fr/.Rule 8: hreflang Header Injection
Link headers for alternate languages.Link: <https://example.com/fr/>; rel="alternate"; hreflang="fr", <https://example.com/es/>; rel="alternate"; hreflang="es".Managing traffic from automated agents to protect server resources while ensuring indexability.
Rule 9: Known Good Bot Whitelisting
Rule 10: Aggressive Crawler Rate Limiting
Rule 11: Render-Blocking Resource Bypass
Here is how these rules look in a code format (Pseudo-code based on Service Workers):
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const url = new URL(request.url)
const userAgent = request.headers.get('User-Agent') || ''
const isBot = /googlebot|bingbot/i.test(userAgent)
// --- 1. PATH NORMALIZATION ---
// A. Lowercase Path
if (url.pathname !== url.pathname.toLowerCase()) {
url.pathname = url.pathname.toLowerCase()
return Response.redirect(url.toString(), 301)
}
// B. Remove Tracking Query Params
const trackingParams = ['utm_source', 'fbclid', 'gclid', 'session_id']
let modified = false
trackingParams.forEach(param => {
if (url.searchParams.has(param)) {
url.searchParams.delete(param)
modified = true
}
})
// Note: In production, only redirect if modified and no body was sent yet.
// --- 2. HEADER REWRITES ---
const response = await fetch(request) // Fetch from origin
// Create a mutable response object
const newResponse = new Response(response.body, response)
// A. Security Headers
newResponse.headers.set('Strict-Transport-Security', 'max-age=31536000; includeSubDomains; preload')
// B. X-Robots-Tag for Search Pages
if (url.searchParams.has('sort') || url.searchParams.has('filter')) {
newResponse.headers.set('X-Robots-Tag', 'noindex, follow')
}
// --- 3. BOT ACCOMMODATIONS ---
// A. Verified Bot Bypass (Logic simplified)
// If you are using Cloudflare, this is handled by "Bot Fight Mode"
if (isBot) {
// Ensure we don't block the bot with rate limiting
// Note: Do not block JS/CSS for Googlebot (Critical for rendering)
}
// --- 4. LANGUAGE DETECTION ---
// A. hreflang Headers (Simplified)
// You would normally map this dynamically based on the current path
newResponse.headers.append('Link', `<https://example.com/fr${url.pathname}>; rel="alternate"; hreflang="fr"`)
newResponse.headers.append('Link', `<https://example.com/es${url.pathname}>; rel="alternate"; hreflang="es"`)
return newResponse
}