Skip to main content

Routing and redirects

Vox.Routing builds a lookup index from route projections and records aliases, historical redirects and conflicting URLs.

For the team workflow, see Keep product links working.

Slugs, paths, and URLs​

A slug is one localized path segment such as running-shoes. A path is an application-relative route such as /categories/shoes/running-shoes. An absolute URL additionally has a scheme and authority. Routable entities keep only the segment:

public class Category : IVoxEntity, IVoxRoutable
{
public VoxVarying<IVoxLanguage, string> Slug { get; set; } = new();
public VoxReference<Category>? Parent { get; set; }
}

The default normalizer requires paths to begin with /. It rejects query strings, fragments, backslashes, dot segments, control characters, and encoded separators; collapses repeated/trailing separators; normalizes Unicode; and applies the configured case policy. A slug must be one non-empty segment. Applications can replace IVoxRouteNormalizer, but writes and lookups always use the same instance.

Publish complete route claims​

A normal entity projection publishes a VoxRouteDocument:

[VoxEntityProjection("routes", "1")]
[VoxEntityProjectionPublication]
public class CategoryRoutes(IVoxRouteNormalizer normalizer)
: IVoxEntityProjectionFactory<Category, VoxRouteDocument>
{
public async Task<VoxRouteDocument?> ProjectAsync(
Category category,
IVoxEntityProjectionContext context,
CancellationToken cancellationToken)
{
var languages = await context.GetAllAsync<Language>(cancellationToken);
var claims = new List<VoxRouteClaim>();
foreach (var language in languages)
{
// Walk category.Parent with context.GetAsync<Category>.
// Every read becomes a dependency of this output.
var path = await BuildPathAsync(category, language, context, cancellationToken);
claims.Add(new VoxRouteClaim(
"storefront",
path,
new Dictionary<string, string>
{
[nameof(Language)] = language.Id,
}));
}
return claims.Count == 0 ? null : new VoxRouteDocument(claims);
}
}

This is an unscoped publication: one evaluation publishes all localized routes for the source entity, so context.Contexts is empty. Each claim's Contexts instead records the exact destination context selection that the routing endpoint must use later. The key is the concrete registered context type name (Language here), and the value comes from the language whose path was built. Do not hard-code a language unless the application intentionally publishes only that language.

Space is an application-defined namespace, normally a site or domain; the same path can exist in independent spaces. Contexts is the exact concrete Vox context selection used to deliver the destination. A null Projection selects the entity's root projection, while a name selects an explicit content-delivery projection.

A document can publish localized routes and aliases. It must contain exactly one canonical claim for each space and context selection, and it may not claim the same normalized path twice. Missing localized slugs produce no route unless the application deliberately implements a fallback in its factory.

Duplicate URLs​

Different entities may publish the same path in a space, for example two products whose names give the slug rain-jacket, or a product and a category, or two publications. That's an editorial or integration mistake, not a Vox error: the route store keeps every claim and the publication succeeds. Vox doesn't rewrite slugs, add suffixes, or reject the build.

While a path is shared, a lookup resolves it to one claimant, always the same one: the first in the store's order of the owners (entity type, then entity id, then publication, then projection id). The order is the store's: the Entity Framework store sorts with the database's collation, the in-memory store ordinally, so two stores can choose differently for ids that differ only in case. Because the order decides and not who claimed the URL first, a new product whose id sorts first takes over an established product's live URL when it claims the same path. Once an editor changes one of the slugs, each entity resolves at its own URL again. A previewed entity resolves at its own URLs in preview, so an editor who previews the other claimant sees it there, while visitors see the chosen one.

Editors learn about duplicates from an assessment: routing registers the scheduled assessment vox-duplicate-urls for each entity type that has a route publication. Every claimant of a shared URL gets a warning with one duplicate-url finding per shared URL, keyed by space and path, also an entity that didn't change when another entity claimed its URL. The finding names another claimant, and its details hold the claim's contexts, the first few other claimants and their total count, so a URL that thousands of entities share still gives a small finding of each. The assessment runs every hour, set by VoxRoutingOptions.DuplicateUrlAssessmentInterval, so a finding appears or disappears up to that long after the URLs change. Each run groups every route row by path, which reads the whole path index of the routes table: seconds for a few million routes, but a large catalogue with several routed entity types can lengthen the interval to spend less on it; reassessing it in the admin UI or through the reassess endpoints runs it at once. See scheduled assessments. Resolution never depends on the findings.

Dependency-driven hierarchy updates​

Parent discovery is explicit application logic. Read every parent relation, slug, prefix setting, or site entity via the projection context. Vox records those reads. Changing an ancestor slug or moving a branch then republishes each dependent descendant route without saving the descendants, incrementing their entity versions, or writing unrelated history.

Page-by-page publication​

The publication processor reads the sources of a build a page at a time, and each page of route documents is applied to the route store at once, in a transaction of its own, so a build never holds more than a page in memory. A build doesn't become visible all at once: during a full build of a large catalog, lookups see a mix of old and new routes until the last page is applied. A build that fails part way leaves the pages it applied visible; the processor keeps a failed incremental run's sources pending and requests a failed full build again, and applying the same writes again changes nothing, so the routes converge. After each page, the sink announces a vox-route dependency change for every entity of the page, so what reads routes, such as image URLs, is recalculated. The route sink has the key vox-routes in every route publication, so a route publication can have sinks of the application's own beside it, see Several sinks.

An owner can take over a path from another within one build. If the new owner's page comes first, the path is briefly shared and resolves by the order above; the end result is the same. A full build removes the owners of its publication that it didn't produce through the processor's deletes of stale outputs, which come from the publication's journal, without creating redirects for them.

Because those deletes come from the journal in Vox's database, the routing tables must be reset together with Vox's database. If Vox's database is reset and a separate routing database isn't, the routes of entities that no longer exist stay and resolve to entities that are gone, which delivery answers with 404.

Route storage and high-traffic delivery​

IVoxRouteStore is the storage boundary used by route publication and lookup. ApplyAsync applies a page of owner writes (an owner with its complete document, or null to remove its claims; the last write of an owner in a page wins) and makes it visible; applying the same page again must change nothing. The store keeps every claim of a shared path, resolves it to the first in its order, retains redirects by the rules below, and lists the entities that claim shared paths (ListSharedRoutesAsync) for the duplicate URL assessment. The routing rules are shared: VoxRouteStateEditor takes the slice of the store a page touches and returns the changes to apply. Resolution reads use the same normalized keys written by the publication sink.

The bundled durable implementation is EntityFrameworkVoxRouteStore, registered with AddEntityFrameworkRouting. It stores routes and redirects in SQL and is the default choice for ordinary installations. A page reads and writes only what it touches: the previous claims of its owners, the claims at the paths they claimed and claim, and the redirects at and to those paths, so a one-product slug fix costs the same in a table of ten routes and of millions. Each page is a transaction at the database's default isolation, without a lock across pages. InMemoryVoxRouteStore is also available for tests and ephemeral hosts, but it loses the complete route index when the process stops.

The routing tables are created once and never migrated: after an upgrade that changes them, reset them together with Vox's database.

Applications with a high-volume or geographically distributed delivery tier can replace the SQL store by registering their own IVoxRouteStore implementation after AddVoxRouting. Register exactly one route store: Vox validates this when Build() runs. A custom store can use Redis, a dedicated routing database, or another lookup system as long as it implements the same members with the same semantics.

vox.AddVoxRouting();
vox.Services.AddScoped<IVoxRouteStore, HighTrafficRouteStore>();

An official Redis-backed IVoxRouteStore implementation is coming.

Aliases and historical redirects​

An alias is a current VoxRouteKind.Alias claim owned by the document and resolves to its canonical claim. A historical redirect is created by the default IVoxRedirectPolicy only when one removed canonical route has exactly one replacement in the same space and equivalent contexts. Redirect chains are flattened to the latest canonical destination, and redirects to a path that nobody claims any more are removed.

Deletion, unpublishing, removing a language, and ambiguous split/merge changes do not invent redirects. A redirect is stored at a path only while nobody claims it: a new current claim may reclaim a historical redirect source, and the current route wins. Redirect delivery uses 308 by default, or 301 when explicitly configured.

At a shared URL, redirects follow the claimant that visitors saw there. With A as the chosen claimant of /products/rain-jacket and B as the other:

  • A moves to /products/red-rain-jacket and B stays: the URL now shows B, and no redirect is stored.
  • B moves away and A stays: nothing changes at the URL.
  • Both move in the same page: nobody claims the URL any more, and it redirects to A's new URL.
  • A is deleted and B moves away in the same page: no redirect, since deletions never create one.
  • A moves onto a path that C claims and C sorts first: the redirect is created as usual and leads to C.
  • An existing redirect to a URL that becomes shared stays, and lands on the chosen claimant.

Redirect history at a URL that was shared is best effort. When the claimants' moves arrive in different pages, or in concurrent runs of different publications, the outcome depends on their order: if A's move is applied first, B still claims the URL and no redirect is stored, and when B moves later the URL redirects to B's new URL. If both publications apply their moves at the same moment, the URL may end up without a redirect.

Projection delivery​

Register the add-on, and app.MapVox() maps an explicit catch-all at /content/{**path}, or at options.Pattern:

vox.AddVoxRouting()
.AddEntityFrameworkRouting(options => options.ConfigureDbContext = ConfigureRoutes)
.AddVoxRoutingApi(options => options.DefaultSpace = "storefront");

The endpoint resolves the stored entity, contexts, and projection, then uses the same delivery component as the entity-ID projection API. Read permissions, not-found behavior, sensitive-value redaction, rich-text formatting, and reference expansion therefore remain consistent. Stored contexts are authoritative; callers cannot override them with ?context=.

The route index contains published content only, and drafts and releases are never mixed into public routing. Publication state and failures remain visible through the entity-projection-publication jobs and API.

With visual preview, a site's server reads the pages of an editor's preview through the same endpoint with a preview grant, Vox-Preview: {grant}, next to its API key. The grant's entity then resolves by its route projection evaluated in the grant's selection, so its page resolves even when its slug is new or changed in the draft, and every destination is delivered in the grant's selection. Other entities resolve by their published routes. AddVoxPreview maps the route spaces to the sites their pages are opened on.

The endpoint is VoxRouteDelivery, which an application can also call from an endpoint of its own.