Sitemaps on Cloudflare Workers
Generate, deploy, and verify an Astro sitemap on Cloudflare Workers with PhantomWP.
Sitemaps on Cloudflare Workers
Astro generates a sitemap during the production build. To create absolute URLs, the sitemap integration needs the site's production URL in astro.config.mjs.
Set this URL in SEO Settings and commit it with the rest of your project. PhantomWP does not create a server-side commit to astro.config.mjs solely to add site, because that commit could conflict with config changes still open in your local editor.
PhantomWP Projects
New PhantomWP projects already include @astrojs/sitemap and the sitemap() integration. Complete the site URL after Cloudflare assigns the project its production address:
- Deploy the project once from the PhantomWP dashboard and wait for the GitHub Actions workflow to finish.
- Open SEO Settings.
- Click Use deployment URL, or enter the complete HTTPS URL for a custom domain.
- Save the settings.
- Commit and push the updated
astro.config.mjsandpublic/robots.txtfiles. - Deploy again so Astro builds the sitemap with the saved production URL.
The first deployment configures Cloudflare and discovers the project's workers.dev address. Saving SEO Settings writes that address locally, so it follows the same review and commit flow as your other project changes.
Existing Cloudflare Deployments
If an existing deployment has no sitemap, open SEO Settings and follow steps 3-6 above. Redeploying by itself does not add a missing site value to a static project's astro.config.mjs.
You do not need to update the PhantomWP local development container for sitemap generation. GitHub Actions must be enabled for the repository, and the deployment workflow must complete successfully.
Use A Custom Domain
Set the custom domain before the production build so every sitemap entry uses the canonical URL:
- Open the project in PhantomWP.
- Open SEO Settings and set Site URL to the complete HTTPS URL, such as
https://www.example.com. - Save the settings.
- Commit and push the updated
astro.config.mjsandpublic/robots.txtfiles. - Deploy the project again.
SEO Settings also adds the sitemap location to public/robots.txt:
Sitemap: https://www.example.com/sitemap-index.xmlAdding a custom domain in Cloudflare does not update Astro's site value by itself. Complete the steps above whenever the canonical domain changes.
Imported Or Customized Projects
Imported Astro projects must have the sitemap integration installed and configured. Install it with the project's package manager. For npm projects, run:
npm install @astrojs/sitemapThen configure both site and sitemap() in astro.config.mjs:
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';
export default defineConfig({
site: 'https://www.example.com',
integrations: [sitemap()],
});SEO Settings can add a missing site value when the file uses export default defineConfig({ ... }). Configurations that use a factory function, wrapper, or another custom structure may require you to add site manually.
Verify The Sitemap
After the Cloudflare deployment finishes, open:
https://your-production-domain.example/sitemap-index.xmlThe response should be XML and should reference one or more child sitemap files, such as sitemap-0.xml. Open a child sitemap and confirm that its page URLs use the expected production domain.
The sitemap is generated during npm run build. A missing sitemap in the local development preview does not indicate a deployment problem.
Troubleshooting
The Production Sitemap Returns 404
Check the latest GitHub Actions run first. Confirm that the workflow completed, astro.config.mjs contains site, and @astrojs/sitemap is present in both the project dependencies and Astro integrations. Then deploy again.
The Sitemap Uses The Workers Domain
Set the custom domain in SEO Settings, commit and push the generated changes, and deploy again.
Robots.txt Does Not Advertise The Sitemap
Set Site URL in SEO Settings, then commit and push astro.config.mjs and public/robots.txt. Astro uses the config value to generate the sitemap, while robots.txt advertises its location.
For general deployment failures, see Deployment Troubleshooting.