The product owns the route: changing URLs without rewriting the capability
Two profiles of one Symfony Kernel read shared content through different routes, with trusted hosts, canonical URLs, and old-slug redirects.
A library gains a convenient method: read an article and return its address at the same time. The first site is happy. The second wants the same capability under /library, while a third uses separate domains for different products. Site names, prefixes, and exceptions gradually appear inside the method. A navigation change now requires a new release of code that was only supposed to read content.
We can separate this dependency. The shared use case answers a request for available content. The product decides how a reader reaches its presentation. Between them, it is enough to pass an intent: open a particular article in a particular locale. The host and path structure appear later, at the navigation boundary.
Continue the same article_demo on Symfony 8.1 and PHP 8.4+: two synthetic Journal and Academy profiles run in one Kernel. They share reading behaviour while owning distinct route names, hosts, and URL structures. This is not two independent installations.
Content has an identity; the site has an address
The teaching card needs four values: a stable id, a locale, the current localized slug, and a title. It contains no hostname, /read prefix, or ready-made absolute URL. The ReadCard use case reads a synthetic catalogue and returns a card only for an available translation. It neither imports Symfony Routing nor knows the product name.
In this model, the slug belongs to localized content. This is a deliberate choice: both products use the same editorial slug. A product with its own page names would need a separate mapping. Leaving the host out of a DTO does not create that mapping by itself.
The intent “read note-a in English” does not prove that an English version exists, either. The use case first obtains an available card; only then does the navigation adapter build a link. A hidden translation does not acquire a URL merely because the router can compose a string from supplied parameters.
| Decision | Owner in the example |
|---|---|
| Which article and translation are available | Reading use case |
| Which data the card needs | Card contract |
| What the route is called and where it lives | Individual application |
| Which host is canonical | Product configuration |
| How an old slug is handled | Product HTTP presentation |
One intent, two named routes
Journal uses app_reading_journal with HTTPS host journal.example and path /read/{_locale}/{id}/{slug}. Academy uses app_reading_academy, host academy.example, and /{_locale}/library/{id}/{slug}. These are distinct route names in one router, defined by attributes on ReadingController. Both accept GET and uk/ru/en.
The domains are synthetic: Kernel tests need no DNS records or real HTTPS server. Symfony Routing describes host requirements and URL generation by name. Trusted composition selects the profile rather than an arbitrary request parameter.
The navigation adapter adds the URL
ReadingLinks lives next to the product's HTTP presentation. Its complete implementation is small:
<?php
declare(strict_types=1);
namespace App\Reading;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
final readonly class ReadingLinks
{
public const JOURNAL_ROUTE = 'app_reading_journal';
public const ACADEMY_ROUTE = 'app_reading_academy';
public function __construct(private UrlGeneratorInterface $urls, private string $routeName)
{
if (!in_array($routeName, [self::JOURNAL_ROUTE, self::ACADEMY_ROUTE], true)) {
throw new \InvalidArgumentException('Select a trusted reading route.');
}
}
public function forCard(Card $card): string
{
return $this->urls->generate($this->routeName, [
'id' => $card->id,
'_locale' => $card->locale,
'slug' => $card->slug,
], UrlGeneratorInterface::ABSOLUTE_URL);
}
}
The adapter passes the locale explicitly and takes the slug from the current card. It does not copy arbitrary HTTP request parameters into the address, so utm_source and next do not enter the canonical URL. The important property of this placement is that the adapter or route can change with the product without changing ReadCard.
Add both profiles to the existing application. Merge the entries below into the existing services: block, preserving earlier configuration. The names app.reading_links.journal and app.reading_links.academy bind one adapter to different trusted route names. This does not test installing or releasing a shared Composer package.
services:
App\Reading\ReadCard:
arguments:
$fixturePath: '%kernel.project_dir%/fixtures/reading-cards.json'
app.reading_links.journal:
class: App\Reading\ReadingLinks
arguments:
$routeName: 'app_reading_journal'
app.reading_links.academy:
class: App\Reading\ReadingLinks
arguments:
$routeName: 'app_reading_academy'
App\Controller\ReadingController:
arguments:
$journalLinks: '@app.reading_links.journal'
$academyLinks: '@app.reading_links.academy'
A canonical URL starts with trusted configuration
The HTML response contains one absolute canonical link. For the Ukrainian and English versions, it points to the respective translation rather than always pointing to Ukrainian content. Google describes canonical as a signal about the preferred address among duplicates; it does not guarantee that search will choose that address. Full translations also need a separate policy for language alternatives. See the canonical guidance.
The route itself specifies the host and HTTPS in this example. The generator does not choose the primary domain from an arbitrary request header. Requests with a foreign host should not match the route. A real deployment must also align its reverse proxy, trusted hosts, and forwarded headers; this lab does not test network configuration.
Explicit configuration matters outside HTTP as well. A console use case should not accidentally generate localhost or reuse the locale of a previous request. Here, the host, scheme, and _locale are supplied directly. For routes without their own host, Symfony also documents default_uri as the generation context for commands.
An old slug does not change identity
Suppose an article's title has been edited. The URL contains a stable id, so the controller can find the card independently of the old slug. It first checks whether the requested translation is available. A missing or hidden card returns 404. An existing card with an outdated slug produces a 301 response pointing to this product's current address.
The same ReadingLinks builds the redirect target. A reader-supplied next parameter does not control Location. After one redirect, the target should return 200 with a canonical URL identical to that target. This prevents a redirect from sending the reader to one address while the HTML declares a different primary address.
The rule deliberately accepts any syntactically valid slug for a known id and redirects it to the current one. It does not store slug history. A product that accepts only recognized historical addresses needs a different contract with a separate redirect store.
Changing a prefix used by published addresses needs separate migration routes. A generator for new URLs does not automatically preserve old inbound links; two profiles do not constitute a completed SEO migration.
Check the address together with its destination
27 tests with 66 assertions checked the composition: 13 scenarios per profile plus one test for trusted route selection. WebTestCase exercises HTTP behaviour in one Kernel without a network server.
The checks cover content, locale, one canonical link, exclusion of query parameters, old slugs, and redirect-target availability. Negative cases cover a hidden translation, unknown card, unsupported locale, foreign host, and disallowed HTTP method. Generation outside a request retains the correct domain.
This evidence applies to two profiles of one application. It does not establish independent deployments, DNS, TLS, Google indexing, browser rendering, authorization, or cache updates. A product owner changes navigation while the use case receives the same identity and returns the same content.