Next.js Multilingual Sitemap Optimization: Dodge Redirect Issues & Boost SEO
Introduction Ever been annoyed by this? You put in the work to generate a sitemap.xml for your multilingual site, only to check it on Ahrefs or Google Search Console and—bam!—a ton of “redirect issue” warnings. Take my site, solomakerstudio.com, for example. Links without a language code (like solomakerstudio.com/) all 301 redirect to the default language (say, solomakerstudio.com/en/). It’s not just annoying—it can make search engines think your site’s messy, hurting your SEO. No stress, though! This article’s gonna walk you through optimizing your multilingual sitemap.xml to squash those redirect issues and make your site a search engine’s best friend. It’s super practical, beginner-friendly, and even if you’re new to SEO, you’ll be able to follow along! Why Does sitemap.xml Have Redirect Issues? Let’s get to the root of the problem. Many multilingual sites (using subdirectories like /en or /zh) set non-localized links (e.g., solomakerstudio.com/) to auto-redirect to a default language (like /en/). That’s fine for users, but it causes headaches in sitemap.xml: Search engines hate redirects: If solomakerstudio.com/ is in your sitemap but redirects to /en/, crawlers have to jump through an extra hoop. It slows them down and makes your sitemap look less “direct.” SEO tools throw warnings: Tools like Ahrefs or SEMrush flag redirects in your sitemap as “issues,” which is just frustrating. Duplicate content risks: If both / and /en/ are in your sitemap, search engines might think they’re separate pages, diluting your page’s ranking power. The fix? Only include final, non-redirecting URLs in your sitemap.xml—no “middleman” links that trigger redirects. 4 Practical Steps to Optimize Your sitemap.xml Alright, let’s get to the good stuff! Here are four dead-simple steps to make your multilingual sitemap clean and SEO-friendly. Step 1: Only Include Localized Links The golden rule: Don’t put non-localized links (like solomakerstudio.com/) in your sitemap.xml. Only include URLs with language subdirectories, like this: https://solomakerstudio.com/en/ 2025-04-17 weekly 0.8 https://solomakerstudio.com/zh/ 2025-04-17 weekly 0.8 How to do it? CMS users (e.g., WordPress): Check your sitemap plugin (like Yoast SEO or Rank Math) settings to ensure it only generates URLs with language codes (e.g., /en/ or /zh/). Custom scripts: If you’re generating your sitemap manually, tweak the code to filter out non-localized URLs. For a Next.js project, add a sitemap.tsx file in the root and use this script: import type { MetadataRoute } from 'next'; import { appConfig } from '@/lib/appConfig'; // Helper function to generate localized URLs const getLocalizedUrl = (baseUrl: string, path: string, locale: string) => { const localePath = `/${locale}`; const routePath = path === '' ? '' : `/${path}`; return `${baseUrl}${localePath}${routePath}`; }; export default async function sitemap(): Promise { // Define static routes const staticRoutes = [ { path: '', changeFrequency: 'daily' as const, priority: 1 }, { path: 'tools', changeFrequency: 'daily' as const, priority: 0.9 }, ]; const sitemapData: MetadataRoute.Sitemap = []; // Get supported languages const locales = appConfig.i18n.locales; // Loop through languages to generate localized links for (const locale of locales) { staticRoutes.forEach(route => { sitemapData.push({ url: getLocalizedUrl(BASE_URL, route.path, locale), lastModified: new Date(), changeFrequency: route.changeFrequency, priority: route.priority, }); }); } // All generated links include language prefixes return sitemapData; } Pro tip: This applies to your homepage too! If solomakerstudio.com/ redirects to solomakerstudio.com/en/, only include the /en/ version in your sitemap. Step 2: Add hreflang Tags to Clarify Language Versions For multilingual sites, you gotta tell search engines which pages are the same content in different languages. That’s where hreflang tags come in. Add them to your sitemap.xml like this: https://solomakerstudio.com/en/ 2025-04-17 https://solomakerstudio.com/zh/ 2025-04-17 Why bother? Tells Google which page is English, which is Chinese, preventing duplicate content issues. Improves user experience by helping search engines serve the right language version based on user preferences. Saves crawler resources—search engines have tons of sites to crawl, so making their job easier helps your site get indexed faster! How to add them? WordPress users: Plugins like Yoast SEO or Polylang can auto-generate sitemaps with hreflang tags. Manual sitemaps: Make sure your sitemap XML includes the xmlns:xhtml="http://www.w3.org/1999/xhtml" namespace, like this: Step 3: Ensure Redirects Use 301 If non-localized li

Introduction
Ever been annoyed by this? You put in the work to generate a sitemap.xml for your multilingual site, only to check it on Ahrefs or Google Search Console and—bam!—a ton of “redirect issue” warnings. Take my site, solomakerstudio.com
, for example. Links without a language code (like solomakerstudio.com/
) all 301 redirect to the default language (say, solomakerstudio.com/en/
). It’s not just annoying—it can make search engines think your site’s messy, hurting your SEO.
No stress, though! This article’s gonna walk you through optimizing your multilingual sitemap.xml to squash those redirect issues and make your site a search engine’s best friend. It’s super practical, beginner-friendly, and even if you’re new to SEO, you’ll be able to follow along!
Why Does sitemap.xml Have Redirect Issues?
Let’s get to the root of the problem. Many multilingual sites (using subdirectories like /en
or /zh
) set non-localized links (e.g., solomakerstudio.com/
) to auto-redirect to a default language (like /en/
). That’s fine for users, but it causes headaches in sitemap.xml:
-
Search engines hate redirects: If
solomakerstudio.com/
is in your sitemap but redirects to/en/
, crawlers have to jump through an extra hoop. It slows them down and makes your sitemap look less “direct.” - SEO tools throw warnings: Tools like Ahrefs or SEMrush flag redirects in your sitemap as “issues,” which is just frustrating.
-
Duplicate content risks: If both
/
and/en/
are in your sitemap, search engines might think they’re separate pages, diluting your page’s ranking power.
The fix? Only include final, non-redirecting URLs in your sitemap.xml—no “middleman” links that trigger redirects.
4 Practical Steps to Optimize Your sitemap.xml
Alright, let’s get to the good stuff! Here are four dead-simple steps to make your multilingual sitemap clean and SEO-friendly.
Step 1: Only Include Localized Links
The golden rule: Don’t put non-localized links (like solomakerstudio.com/
) in your sitemap.xml. Only include URLs with language subdirectories, like this:
https://solomakerstudio.com/en/
2025-04-17
weekly
0.8
https://solomakerstudio.com/zh/
2025-04-17
weekly
0.8
How to do it?
-
CMS users (e.g., WordPress): Check your sitemap plugin (like Yoast SEO or Rank Math) settings to ensure it only generates URLs with language codes (e.g.,
/en/
or/zh/
). -
Custom scripts: If you’re generating your sitemap manually, tweak the code to filter out non-localized URLs. For a Next.js project, add a
sitemap.tsx
file in the root and use this script:
import type { MetadataRoute } from 'next';
import { appConfig } from '@/lib/appConfig';
// Helper function to generate localized URLs
const getLocalizedUrl = (baseUrl: string, path: string, locale: string) => {
const localePath = `/${locale}`;
const routePath = path === '' ? '' : `/${path}`;
return `${baseUrl}${localePath}${routePath}`;
};
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
// Define static routes
const staticRoutes = [
{ path: '', changeFrequency: 'daily' as const, priority: 1 },
{ path: 'tools', changeFrequency: 'daily' as const, priority: 0.9 },
];
const sitemapData: MetadataRoute.Sitemap = [];
// Get supported languages
const locales = appConfig.i18n.locales;
// Loop through languages to generate localized links
for (const locale of locales) {
staticRoutes.forEach(route => {
sitemapData.push({
url: getLocalizedUrl(BASE_URL, route.path, locale),
lastModified: new Date(),
changeFrequency: route.changeFrequency,
priority: route.priority,
});
});
}
// All generated links include language prefixes
return sitemapData;
}
Pro tip: This applies to your homepage too! If solomakerstudio.com/
redirects to solomakerstudio.com/en/
, only include the /en/
version in your sitemap.
Step 2: Add hreflang Tags to Clarify Language Versions
For multilingual sites, you gotta tell search engines which pages are the same content in different languages. That’s where hreflang
tags come in. Add them to your sitemap.xml like this:
https://solomakerstudio.com/en/
rel="alternate" hreflang="en" href="https://solomakerstudio.com/en/" />
rel="alternate" hreflang="zh" href="https://solomakerstudio.com/zh/" />
2025-04-17
https://solomakerstudio.com/zh/
rel="alternate" hreflang="en" href="https://solomakerstudio.com/en/" />
rel="alternate" hreflang="zh" href="https://solomakerstudio.com/zh/" />
2025-04-17
Why bother?
- Tells Google which page is English, which is Chinese, preventing duplicate content issues.
- Improves user experience by helping search engines serve the right language version based on user preferences.
- Saves crawler resources—search engines have tons of sites to crawl, so making their job easier helps your site get indexed faster!
How to add them?
-
WordPress users: Plugins like Yoast SEO or Polylang can auto-generate sitemaps with
hreflang
tags. -
Manual sitemaps: Make sure your sitemap XML includes the
xmlns:xhtml="http://www.w3.org/1999/xhtml"
namespace, like this:
Step 3: Ensure Redirects Use 301
If non-localized links (like solomakerstudio.com/
) redirect, make sure they use 301 permanent redirects, not 302 temporary ones. Why? A 301 tells search engines, “This page has moved for good,” passing SEO juice smoothly.
How to check?
- Open your browser’s developer tools (F12 -> Network tab), visit
solomakerstudio.com/
, and check if the status code is 301. - Or use an online tool like redirect-checker.org to confirm.
How to fix?
- Server config (Nginx/Apache): Ensure redirects are set to 301. For Nginx, it looks like this:
rewrite ^/$ /en/ permanent;
- CMS users: Check your language-switching plugin to confirm it’s using 301 redirects.
-
Next.js example (e.g.,
solomakerstudio.com
hosted on Vercel): Use a custommiddleware.ts
file:
import { NextRequest, NextResponse } from 'next/server';
import createMiddleware from 'next-intl/middleware';
import { appConfig } from './lib/appConfig';
const intlMiddleware = createMiddleware({
locales: appConfig.i18n.locales,
defaultLocale: appConfig.i18n.defaultLocale,
localePrefix: 'always',
});
export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl;
// Handle root path (/) for 301 redirect based on Accept-Language
if (pathname === '/') {
const acceptLanguage = request.headers.get('accept-language') || '';
let targetLocale = appConfig.i18n.defaultLocale; // Fallback
// Match language based on Accept-Language header
if (acceptLanguage.includes('zh')) {
targetLocale = 'zh';
} else if (acceptLanguage.includes('en')) {
targetLocale = 'en';
}
// Perform 301 redirect
const redirectUrl = new URL(`/${targetLocale}`, request.url);
return NextResponse.redirect(redirectUrl, 301);
}
return intlMiddleware(request);
}
export const config = {
matcher: [
'/((?!api|_next|.*\\..*).*)',
'/rss.xml',
'/:locale/rss.xml',
'/admin/:path*',
],
};
Step 4: Validate Your sitemap.xml
Before submitting your shiny new sitemap.xml, double-check it to avoid any oopsies.
How to validate?
- Submit your sitemap to Google Search Console’s “Sitemaps” tool and check the “Coverage” report after a few days for errors.
- Run Ahrefs’ Site Audit to see if there are any redirect warnings in your sitemap.
- Locally, use an XML validator (like xmlvalidation.com) to ensure your sitemap’s format is correct.
Pro tip: After submitting to Google Search Console, hit “Resubmit” to nudge crawlers to grab the updated version. Here’s what our optimized sitemap looked like after running it through Ahrefs:
Extra Tips to Keep in Mind
A few bonus pointers to make your sitemap even better:
- Dynamic sitemaps: If your site has tons of pages, use a script or plugin to auto-generate your sitemap—saves time!
-
Regular updates: Keep your sitemap fresh with accurate
dates whenever your site changes. - Multilingual plugins: For WordPress, plugins like WPML or Polylang make multilingual sitemaps a breeze—set them up and relax.
Wrapping Up
Fixing your multilingual sitemap.xml isn’t rocket science. The key? Skip redirecting links, use localized URLs, add hreflang tags, and stick to 301 redirects. Follow these four steps, and your sitemap will be squeaky clean—no more Ahrefs warnings, and Google’s crawlers will love your site.
Give it a shot! If you hit any snags (like how to tweak your CMS or code), just let me know, and I’ll break it down for you!