XML Sitemap Guide
Hjælp søgemaskiner med at finde og indexere dine vigtigste sider
Hvad er en XML Sitemap?
En XML sitemap er en fil der lister alle vigtige URLs på dit website. Den fortæller søgemaskiner hvilke sider der findes, hvornår de blev opdateret, og hvor vigtige de er i forhold til andre sider.
Fordele:
- • Hjælper Google med at finde nye og opdaterede sider
- • Særligt vigtigt for store sites eller sites med dårlig internal linking
- • Accelererer indexering af nyt indhold
- • Giver metadata om hver URL (last modified, priority)
- • Required for Google News og andre specialized services
Basic Sitemap Structure
Minimal XML Sitemap
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://example.com/</loc>
<lastmod>2024-01-15</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://example.com/about</loc>
<lastmod>2024-01-10</lastmod>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://example.com/blog/article</loc>
<lastmod>2024-01-20</lastmod>
<changefreq>weekly</changefreq>
<priority>0.6</priority>
</url>
</urlset>
Sitemap Tags
<loc> (required)
URL til siden. Skal være absolut URL (inkl. https://).
<loc>https://example.com/page</loc>
<lastmod> (optional)
Sidste modificeringsdato i W3C format (YYYY-MM-DD).
<lastmod>2024-01-15</lastmod>
<changefreq> (optional)
Hvor ofte siden ændres: always, hourly, daily, weekly, monthly, yearly, never
<changefreq>weekly</changefreq>
Note: Google ignorerer ofte denne tag
<priority> (optional)
Relativ prioritet (0.0 til 1.0). Default er 0.5.
<priority>0.8</priority>
Note: Google bruger sjældent denne værdi
Sitemap Index (for store sites)
Hvis du har over 50,000 URLs eller din sitemap er over 50MB, split den op i flere sitemaps og brug en sitemap index fil:
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://example.com/sitemap-posts.xml</loc>
<lastmod>2024-01-15</lastmod>
</sitemap>
<sitemap>
<loc>https://example.com/sitemap-pages.xml</loc>
<lastmod>2024-01-10</lastmod>
</sitemap>
<sitemap>
<loc>https://example.com/sitemap-products.xml</loc>
<lastmod>2024-01-20</lastmod>
</sitemap>
</sitemapindex>
Image Sitemap Extension
Tilføj billede information til din sitemap for bedre billede indexering:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<url>
<loc>https://example.com/blog/article</loc>
<image:image>
<image:loc>https://example.com/images/photo.jpg</image:loc>
<image:title>Photo Title</image:title>
<image:caption>Photo description</image:caption>
</image:image>
</url>
</urlset>
Next.js Sitemap Generation
Automatisk med next-sitemap
1. Installer next-sitemap:
npm install next-sitemap
2. Opret next-sitemap.config.js:
/** @type {import('next-sitemap').IConfig} */
module.exports = {
siteUrl: process.env.SITE_URL || 'https://example.com',
generateRobotsTxt: true,
generateIndexSitemap: true,
exclude: ['/admin/*', '/private/*'],
robotsTxtOptions: {
policies: [
{
userAgent: '*',
allow: '/',
disallow: ['/admin', '/private'],
},
],
},
}
3. Tilføj postbuild script:
"postbuild": "next-sitemap"
Manuel Next.js Sitemap (App Router)
// app/sitemap.ts
import { MetadataRoute } from 'next'
export default function sitemap(): MetadataRoute.Sitemap {
const baseUrl = 'https://example.com'
// Static pages
const staticPages = [
'',
'/about',
'/contact',
].map((route) => ({
url: `${baseUrl}${route}`,
lastModified: new Date(),
changeFrequency: 'monthly' as const,
priority: route === '' ? 1 : 0.8,
}))
// Dynamic pages (fetch from database)
const posts = await getPosts()
const postPages = posts.map((post) => ({
url: `${baseUrl}/blog/${post.slug}`,
lastModified: new Date(post.updatedAt),
changeFrequency: 'weekly' as const,
priority: 0.6,
}))
return [...staticPages, ...postPages]
}
Submission til Search Engines
1. Via robots.txt (anbefalet)
Sitemap: https://example.com/sitemap.xml
Søgemaskiner finder automatisk sitemap via robots.txt
2. Google Search Console
- • Gå til Sitemaps i venstre menu
- • Indtast sitemap URL og klik "Submit"
- • Monitor status og errors
3. Bing Webmaster Tools
- • Gå til Sitemaps
- • Submit sitemap URL
4. HTTP Request (for updates)
http://www.google.com/ping?sitemap=https://example.com/sitemap.xml
Hvad skal IKKE i sitemap?
- • Redirect URLs - Kun inkluder final destination
- • Non-canonical URLs - Kun canonical versions
- • Noindex pages - Sider med meta robots noindex
- • Blocked URLs - Sider blocked i robots.txt
- • 404 pages - Kun valid, accessible URLs
- • Low-quality pages - Thin content, duplicate pages
- • Paginated pages - Brug rel="next/prev" eller vis-all
Best Practices
✓ Gør dette
- • Kun inkluder indexable URLs
- • Brug absolute URLs
- • Opdater lastmod når indhold ændres
- • Split store sites i multiple sitemaps
- • Reference sitemap i robots.txt
- • Monitor sitemap errors i Search Console
✗ Undgå dette
- • Over 50,000 URLs per sitemap
- • Over 50MB per sitemap file
- • Inkluder blocked eller noindex URLs
- • Glem at opdatere efter site changes
- • Inkluder redirect URLs
- • Ignorer Search Console errors