Перейти к содержимому
Skip to content
← All articles

XML Sitemap Guide: Creation, Structure, and Best Practices

XML Sitemap Guide: Everything You Need to Know

An XML sitemap is a structured file that helps search engines discover, crawl, and index your website's pages efficiently. While search engines can find pages through links, a sitemap provides a direct roadmap to all important content, ensuring nothing is missed during crawling.

Sitemap Structure and Format

XML sitemaps follow a standardized format defined by the sitemaps.org protocol. Each sitemap is an XML document with a specific structure that search engines can parse.

Basic Sitemap Structure

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://example.com/</loc>
    <lastmod>2025-01-15</lastmod>
    <changefreq>weekly</changefreq>
    <priority>1.0</priority>
  </url>
  <url>
    <loc>https://example.com/about</loc>
    <lastmod>2024-12-01</lastmod>
    <changefreq>monthly</changefreq>
    <priority>0.8</priority>
  </url>
</urlset>

XML Tags Explained

TagRequiredDescription
<urlset>YesRoot element encapsulating all URL entries
<url>YesContainer for each individual URL entry
<loc>YesThe absolute URL of the page (must include protocol)
<lastmod>NoLast modification date in W3C datetime format
<changefreq>NoExpected change frequency (daily, weekly, monthly)
<priority>NoRelative priority within your site (0.0 to 1.0)

Sitemap Index Files

For large websites exceeding the 50,000 URL limit per sitemap or the 50MB file size limit, a sitemap index file is used to reference multiple individual sitemaps.

Sitemap Index Structure

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
    <loc>https://example.com/sitemap-pages.xml</loc>
    <lastmod>2025-01-15</lastmod>
  </sitemap>
  <sitemap>
    <loc>https://example.com/sitemap-blog.xml</loc>
    <lastmod>2025-01-14</lastmod>
  </sitemap>
</sitemapindex>

Creating Your Sitemap

Dynamic Generation

For most websites, dynamically generating sitemaps from a database or CMS is the preferred approach. This ensures the sitemap always reflects the current state of your content.

// PHP example: dynamic sitemap generation
header('Content-Type: application/xml; charset=utf-8');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

$pages = $pdo->query("SELECT slug, updated_at FROM pages WHERE is_published = 1");
foreach ($pages as $page) {
    echo '<url>';
    echo '<loc>https://example.com/' . htmlspecialchars($page['slug']) . '</loc>';
    echo '<lastmod>' . date('Y-m-d', strtotime($page['updated_at'])) . '</lastmod>';
    echo '</url>';
}
echo '</urlset>';

Static File Approach

For smaller websites with infrequent content changes, a static XML file manually maintained or generated during the build process can be sufficient.

Submitting Your Sitemap

Submission Methods

  1. Google Search Console — submit directly through the Sitemaps section of your verified property
  2. Bing Webmaster Tools — submit through the Sitemaps section of your verified site
  3. robots.txt reference — add Sitemap: https://example.com/sitemap.xml to your robots.txt file
  4. Ping endpoints — notify search engines programmatically after content changes

robots.txt Integration

User-agent: *
Allow: /

Sitemap: https://example.com/sitemap.xml
Sitemap: https://example.com/sitemap-blog.xml

Common Mistakes to Avoid

Specialized Sitemaps

Image Sitemaps

Image sitemaps help search engines discover images that might not be found through regular crawling, especially images loaded via JavaScript or CSS.

Video Sitemaps

Video sitemaps provide metadata about video content including title, description, duration, thumbnail URL, and expiration date, enabling rich video results in search.

News Sitemaps

News sitemaps are designed for Google News publishers and include articles published within the last 48 hours with metadata like publication name, language, and title.

Monitoring and Maintenance

Conclusion

A well-maintained XML sitemap is a fundamental SEO tool that improves search engine crawling efficiency and helps ensure all your important content gets indexed. By following the correct structure, avoiding common mistakes, and keeping your sitemap updated, you provide search engines with the clearest possible roadmap to your content.

Check your website right now

Check now →
More articles: SEO
SEO
Redirect Chains: How They Affect SEO and Speed
11.03.2026 · 10 views
SEO
Web Accessibility: A Developer's Practical Guide to WCAG Compliance
16.03.2026 · 14 views
SEO
Website Migration Checklist: Avoid SEO and Downtime Pitfalls
16.03.2026 · 13 views
SEO
How HTTPS Impacts SEO Rankings
14.03.2026 · 7 views