# Add an XML Sitemap to a Symfony App

Yes. An agent adds a sitemap.xml to your Symfony app listing every published post in every enabled locale, with a test and a robots.txt entry, in a pull request.

[Run this on Rush](https://cloud.getrush.ai/run/add-sitemap/symfony/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the routing before writing a line. In a Symfony app like symfony/demo, `config/routes.yaml` imports every controller under a `/{_locale}` prefix with `app.locale` as the default, and `config/packages/framework.yaml` enables 30 locales, so each public URL exists once per language, as `/en/blog/posts/{slug}`, `/fr/blog/posts/{slug}` and so on. `src/Controller/BlogController.php` already serves two formats from one action: `blog_index` renders `blog/index.html.twig` and `blog_rss` at `/blog/rss.xml` renders `blog/index.xml.twig` through the `_format` route default, with a `#[Cache(smaxage: 10)]` attribute. `PostRepository::findLatest` returns a page of ten posts (`Paginator::PAGE_SIZE`) whose `publishedAt` is not in the future, and `Post` has a `slug` and a `publishedAt` of type `date_point`. `public/robots.txt` contains only `User-agent: *` and no `Sitemap` line.

The design falls out of that. A sitemap has to live at the root of the site, `/sitemap.xml`, not under a locale prefix, so the agent adds the route in `config/routes.yaml` outside the prefixed import, pointing at a new `SitemapController` with one action that renders `sitemap/index.xml.twig`. The template lists the blog index and every published post, each as a `<url>` with a `<loc>` built by `url('blog_post', {slug, _locale})`, a `<lastmod>` from `publishedAt`, and one `xhtml:link rel="alternate" hreflang` per enabled locale, which is how a multilingual site tells a crawler that the 30 URLs are translations of one page rather than duplicates. The action carries the same `#[Cache(smaxage)]` attribute as the index so the reverse proxy serves it, and the response's content type is `application/xml`.

The query is new but small: a `findAllPublished()` method on `PostRepository` that selects only `slug` and `publishedAt` for posts with `publishedAt <= :now`, ordered by date, without the joins and pagination `findLatest` carries. The enabled locales reach the controller through the `array $enabledLocales` binding `config/services.yaml` already declares for every service, so no new parameter is introduced. The agent adds a `Sitemap: https://.../sitemap.xml` line to `public/robots.txt` using `DEFAULT_URI` from `.env`, which `config/packages/routing.yaml` already uses to generate absolute URLs outside a request.

Tests follow `tests/Controller/BlogControllerTest.php`, whose `testRss` requests `/en/blog/rss.xml`, asserts the `Content-Type` header and counts `item` elements against `Paginator::PAGE_SIZE`. The new `SitemapControllerTest` requests `/sitemap.xml`, asserts `application/xml`, counts one `<loc>` per published post from the fixtures plus the index, and checks that one `<url>` has an `hreflang` link for every enabled locale. The agent also adds `/sitemap.xml` to the `getPublicUrls` data provider in `DefaultControllerTest`. Then it runs what `.github/workflows/tests.yaml` and `lint.yaml` run: `vendor/bin/phpunit`, `php-cs-fixer check`, `bin/console lint:twig templates --env=prod`, `lint:yaml config`, `lint:container` and `phpstan`, and opens the pull request.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Do the work the Linear issue describes: add an XML sitemap to this Symfony app. Read config/routes.yaml, config/packages/framework.yaml, config/packages/routing.yaml, config/services.yaml, .env, src/Controller/BlogController.php, src/Repository/PostRepository.php, src/Entity/Post.php, templates/blog/index.xml.twig, public/robots.txt, tests/Controller/BlogControllerTest.php, tests/Controller/DefaultControllerTest.php, phpunit.dist.xml and .github/workflows/lint.yaml first. Add a SitemapController serving /sitemap.xml at the site root, outside the /{_locale} prefix, with the same Cache attribute the blog index uses and an application/xml content type. Render templates/sitemap/index.xml.twig listing the blog index and every published post, each with a loc built from the blog_post route, a lastmod from publishedAt, and an xhtml:link alternate hreflang entry for every enabled locale, using the enabledLocales binding from services.yaml. Add a findAllPublished method to PostRepository selecting only slug and publishedAt for posts with publishedAt not in the future. Add a Sitemap line to public/robots.txt. Add tests/Controller/SitemapControllerTest.php in the style of BlogControllerTest::testRss, asserting the content type, one loc per published fixture post plus the index, and one hreflang link per enabled locale, and add /sitemap.xml to DefaultControllerTest::getPublicUrls. Run vendor/bin/phpunit, php-cs-fixer check, bin/console lint:twig templates --env=prod, lint:yaml config, lint:container and phpstan, fix anything they report, and open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

The result is a pull request with a new controller, a new Twig template, one repository method, one route entry in `config/routes.yaml`, one line in `public/robots.txt`, a new functional test and one extra URL in the smoke test's data provider. The description shows the first `<url>` block of the generated sitemap with its 30 `hreflang` links, states the content type and the cache header, and notes that `blog_rss` and every HTML page are untouched.

The run's transcript keeps the PHPUnit output, including the existing `testRss` and `testPublicUrls` runs, and the output of each linter from `lint.yaml`: PHP-CS-Fixer, the Twig, YAML and container lints, and PHPStan with the project's `phpstan.dist.neon`. A reviewer can also fetch `/sitemap.xml` from the branch and compare it with the `<loc>` values the test asserts.

Before merging, a reviewer checks that the route is outside the locale prefix so `/sitemap.xml` answers and `/en/sitemap.xml` does not, that unpublished posts (a `publishedAt` in the future) are excluded exactly as `findLatest` excludes them, and that the `hreflang` codes match `enabled_locales` in `framework.yaml`, where `pt_BR` and `sr_Cyrl` need the underscore turned into a hyphen for the attribute.

## Run it on every Linear issue labelled agent

Add an automation to the Project with this prompt and a `linear` trigger on `linear.issue.labeled` with the label your team uses, such as `agent`. The trigger appends the labelled issue to the prompt, so an issue that asks for tag archive pages or the user profile pages in the sitemap too reaches the agent as part of the task; the prompt itself holds no placeholder. A label set by an app integration never fires the trigger, and the automation's `max_runs_per_hour` caps the runs it starts in an hour.

From your own server, send `POST /o/{org}/sessions` with the repository and the issue URL, `https://linear.app/<workspace>/issue/<ID>`, in `resources`, read through your Linear connection, with a `request_id` that is a UUID v5 of the issue id so a redelivered webhook starts no second run. Give the key a `webhook_url` and Rush POSTs `run.completed` with `data.session_url` when the turn ends, so a handler can post the pull request link back on the issue.

## Why run it on Rush?

A sitemap for a 30-locale site is easy to get subtly wrong: a route inside the locale prefix, a locale code with an underscore where the attribute wants a hyphen, or a scheduled post leaking into the list. The only check that catches all three is running the app and reading the XML, and in a Rush sandbox the agent does that with the project's own SQLite database from `.env`, its fixtures, and the PHP 8.4 toolchain the CI matrix uses, before the pull request exists.

What was run is kept: PHPUnit, the six lints from `lint.yaml` and the fetched XML are all in the transcript, and the pull request links to it. A team with several Symfony sites starts one run each from the same request and reviews one pull request each, with the locale list and the routes read from each repository rather than assumed.

## Frequently asked questions

### Why is the sitemap not under /en or /fr like every other URL?

Crawlers look for one sitemap at the site root, and `robots.txt` points at one URL. The agent therefore declares the route in `config/routes.yaml` outside the `controllers` import that carries the `/{_locale}` prefix, and lists every locale's URL inside the file instead, with `hreflang` links tying the translations together.

### Does it include posts scheduled for the future?

No. `findAllPublished` applies the same `publishedAt <= :now` condition `findLatest` uses for the blog index, so a post that is not yet visible on the site is not yet in the sitemap either. The test creates no future post, so the count assertion matches the fixtures.

### Will the RSS feed or the HTML pages change?

No. `blog_rss` keeps rendering `blog/index.xml.twig`, and no HTML template is touched. The only files that change are the new controller and template, the repository method, the route entry, `robots.txt` and the tests.

### Is the sitemap cached?

The action carries the same `#[Cache(smaxage)]` attribute as the blog index, so the HTTP cache in front of the app serves it for that many seconds and the database is not queried on every crawler hit. The value can be raised in the pull request if a new post may take longer to appear.

### What if the site has thousands of posts?

The sitemap protocol caps one file at 50,000 URLs, and with 30 locales per post that is reached sooner than it sounds. For a large site the follow-up on the same session is a sitemap index with one file per locale, which is the natural split given how the routes are prefixed.

## More Symfony jobs

- [Add Two-Factor Authentication to a Symfony App](https://getrush.ai/run/add-two-factor-auth/symfony/)
- [Add User Registration to a Symfony App from a Linear Issue](https://getrush.ai/run/add-user-registration/symfony/)
- [Dockerize a Symfony App](https://getrush.ai/run/dockerize-app/symfony/)

## The same job on other stacks

- [Add a Sitemap to a VitePress Site](https://getrush.ai/run/add-sitemap/vitepress/)
- [Add a Sitemap to an Astro Blog](https://getrush.ai/run/add-sitemap/astro/)
- [Add a Sitemap to a Gatsby Blog](https://getrush.ai/run/add-sitemap/gatsby/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
