> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hadoseo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dynamic Sitemaps with Base44

> Generate dynamic sitemaps for Base44 apps using backend functions

## Overview

Static sitemaps work for simple sites, but if your app has dynamic content (blog posts, products, user profiles), you need a sitemap that updates automatically.

This guide shows you how to create a dynamic sitemap using Base44 backend functions — no manual coding required. Just paste one of the prompts below into Base44 and customize the placeholders.

## When You Need a Dynamic Sitemap

* Blog or content site with new posts
* E-commerce with product pages
* Directory or listing site
* Any app where pages are created from database records

## Prerequisites

* A Base44 project

## Step 1: Choose the Right Prompt

Pick the prompt that best matches your site, then customize the placeholders (marked with `[BRACKETS]`) before pasting it into Base44.

<AccordionGroup>
  <Accordion title="Static-Only Sitemap (no database content)" icon="file-lines" defaultOpen>
    Use this if your site has no database-driven pages — just fixed routes like `/about`, `/pricing`, etc.

    ```text theme={null}
    Create a static sitemap.xml file for my site that has no database-dependent pages. Include:

    1. A sitemap.xml file at the public root directory containing:
       - All public pages with their full canonical URLs using [YOUR_DOMAIN]
       - Appropriate lastmod dates (use today's date or actual last modified)
       - changefreq values (daily for homepage, weekly for main pages, monthly for static content)
       - priority values (1.0 for homepage, 0.8 for main sections, 0.6 for subpages)

    2. These pages:
       - Homepage (/)
       - [List all your static pages, e.g., /about, /pricing, /contact, /features, /blog]

    3. Proper XML structure with:
       - XML declaration
       - urlset with xmlns namespace
       - Properly escaped URLs

    Make sure the sitemap validates against the sitemap protocol specification.
    ```
  </Accordion>

  <Accordion title="Hybrid Sitemap (static pages + some dynamic content)" icon="arrows-split-up-and-left">
    Use this if your site has static pages **and** some dynamic content from your database (under 1,000 items per entity).

    ```text theme={null}
    Create a sitemap system for my site that has both static pages and some dynamic
    content from the database, but not enough to require pagination (under 1000 items
    per entity).

    1. Create a backend function called "sitemap" that:
       - Fetches all dynamic entities from the database in a single query per entity
       - Combines with hardcoded static page URLs
       - Returns complete sitemap XML
       - Caches the response for 1 hour
       - Uses canonical domain: [YOUR_DOMAIN]

    2. Include static pages:
       - [List your static pages, e.g., /, /about, /pricing, /contact]

    3. Include dynamic entities:
       - [List your dynamic routes, e.g., blog posts at /blog?slug=my-post]

    4. For each URL include:
       - loc (full canonical URL)
       - lastmod (from database updated_at or static date)
       - changefreq (based on content type)
       - priority (based on page importance)

    ```
  </Accordion>

  <Accordion title="Backend Function Sitemap (large datasets)" icon="database">
    Use this if you have **1,000+ records** across your entity types (up to 50,000 total URLs).

    ```text theme={null}
    Create a single backend function called "sitemap" that returns a complete
    sitemap with all URLs (up to 50,000). Requirements:

    1. The backend function should:
       - Query all dynamic entities from the database
       - Combine with hardcoded static page URLs
       - Return a single <urlset> XML document with all URLs
       - Include proper lastmod dates from updated_at columns
       - Set appropriate changefreq and priority values
       - Cache the response for 1 hour
       - Return proper XML content-type header
       - Use the canonical domain: [YOUR_DOMAIN]

    2. Include static pages:
       - [List your static pages, e.g., /, /about, /pricing, /contact]

    3. Include these dynamic entity types:
       - [List your entities, e.g., /blog?slug=, /products?id=, /users?username=]

    4. Ensure the total URL count stays under 50,000 (the sitemap protocol limit)
    ```
  </Accordion>

  <Accordion title="Paginated Sitemap (over 50,000 URLs)" icon="layer-group">
    Use this if your total URL count exceeds **50,000** and you need paginated sub-sitemaps.

    ```text theme={null}
    Create a backend function called "sitemap" that returns a <sitemapindex> XML
    document listing paginated sub-sitemap URLs. Requirements:

    1. The "sitemap" function should:
       - Query entity counts from the database to determine pagination
       - Return a <sitemapindex> listing sub-sitemap URLs like:
         /functions/sitemap-posts?page=1, /functions/sitemap-posts?page=2, etc.
       - Include one entry per entity type per page (1000 URLs per page)
       - Cache the response for 1 hour
       - Return proper XML content-type header

    2. For each entity type, create a separate backend function (e.g., "sitemap-posts") that:
       - Accepts a ?page=N query parameter
       - Queries the database for that batch of 1000 records
       - Returns a <urlset> XML document with those URLs
       - Includes proper lastmod dates from updated_at columns
       - Sets appropriate changefreq and priority values
       - Uses the canonical domain: [YOUR_DOMAIN]

    3. Include these entity types:
       - [List your entities, e.g., /blog?slug=, /products?id=, /users?username=]

    ```

    <Warning>
      Google only follows **one level of nesting** in sitemap indexes. Since your static `sitemap.xml` is a `<sitemapindex>` pointing to another `<sitemapindex>` (the backend function), Google won't discover the paginated sub-sitemaps. You **must** proxy `/sitemap.xml` to your sitemap backend function using Hado SEO's routing rules (see Step 4 below) so that Google sees the paginated sub-sitemaps directly.
    </Warning>
  </Accordion>
</AccordionGroup>

<Tip>
  Replace all `[BRACKETS]` with your actual values before pasting into Base44. For example, replace `[YOUR_DOMAIN]` with `https://myapp.com` and list your real pages and entity types.
</Tip>

## Step 2: Verify the Backend Function

After Base44 generates and deploys the code, verify the backend function is returning valid XML.

Your sitemap function will be available at:

```
https://[PROJECT].base44.app/functions/sitemap
```

## Step 3: Create Custom Sitemap in Hado SEO

Base44 does not allow customizing `sitemap.xml` or `robots.txt` directly. Instead, configure a custom sitemap in your Hado SEO dashboard:

1. Go to your [Domain Settings](/dashboard/domain-settings) in the Hado SEO dashboard
2. Add a custom `sitemap.xml` using a `<sitemapindex>` that references your Base44 backend function:
   ```xml theme={null}
   <?xml version="1.0" encoding="UTF-8"?>
   <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
     <sitemap>
       <loc>https://[PROJECT].base44.app/functions/sitemap</loc>
     </sitemap>
   </sitemapindex>
   ```
3. Click **Sync Sitemap** in your dashboard to get your pages listed in the pages table

## Step 4 (Optional): Proxy the Sitemap Through Your Domain

Search engines prefer sitemaps served from your own domain. Use Hado SEO's **routing rules** to proxy `/sitemap.xml` to your Base44 backend function — no code changes needed.

<Steps>
  <Step title="Open Routing Rules">
    In your [Hado SEO Dashboard](https://hadoseo.com/dashboard), select your domain and go to the **Routing Rules** tab.
  </Step>

  <Step title="Add a proxy rule">
    Click **Add Rule** and configure:

    | Field       | Value                                            |
    | ----------- | ------------------------------------------------ |
    | Rule Type   | **Proxy**                                        |
    | Source Path | `/sitemap.xml`                                   |
    | Target URL  | `https://[PROJECT].base44.app/functions/sitemap` |
    | Priority    | `10`                                             |
  </Step>

  <Step title="Verify">
    Visit `https://yourdomain.com/sitemap.xml` in your browser. You should see the XML output from your Base44 function, served from your own domain.
  </Step>
</Steps>

<Info>
  Routing rules are processed by Hado SEO's proxy before your app is hit. The request is forwarded to your Base44 function and the response is returned under your domain — visitors and search engines see `yourdomain.com/sitemap.xml`. Learn more in the [Routing Rules documentation](/dashboard/routing-rules).
</Info>

## Step 5: Test Your Sitemap

### Browser Test

Visit your sitemap URL. You should see properly formatted XML.

### Google Search Console

1. Go to Google Search Console
2. Navigate to Sitemaps
3. Submit your sitemap URL
4. Check for any errors

## Sitemap Best Practices

<AccordionGroup>
  <Accordion title="Keep sitemaps under 50,000 URLs" icon="list-ol">
    Google limits sitemaps to 50,000 URLs or 50MB. For larger sites, use the **Paginated Sitemap** prompt above.
  </Accordion>

  <Accordion title="Update lastmod accurately" icon="calendar">
    Only update `lastmod` when content actually changes. Google may ignore sitemaps that update `lastmod` without real changes.
  </Accordion>

  <Accordion title="Include only indexable pages" icon="filter">
    Don't include:

    * Pages blocked by robots.txt
    * Pages with `noindex` meta tag
    * Redirect URLs
    * Login-required pages
  </Accordion>

  <Accordion title="Use proper URL encoding" icon="code">
    Encode special characters in URLs:

    * `&` becomes `&amp;`
    * `<` becomes `&lt;`
    * `>` becomes `&gt;`
    * `"` becomes `&quot;`
    * `'` becomes `&apos;`
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="SEO Optimization" icon="chart-line" href="/guides/seo-optimization">
    Complete SEO checklist for your app
  </Card>
</CardGroup>
