# Routing

Routing is explicit segment matching in the front controller. There is no route-compiler and no annotation scanning.

## Base path and admin path

Both are configurable. Two rules follow from that:

1. **Never hard-code `/admin`** in links, forms, redirects, assets, JavaScript or documentation examples that represent runtime URLs.
2. **Never hard-code a leading slash or a domain** in an internal link. Use the URL helpers so `/`, `/ask` and any other subdirectory all work without template edits.

Internal paths are written without a leading slash (`'c/' . $slug`) and passed through the URL helper, which applies the base path.

## Public routes

| Path | Purpose |
|---|---|
| `/` | Home feed |
| `/q/{slug}` | Question |
| `/questions/{slug}` | Legacy; permanent redirect to `/q/{slug}` |
| `/ask` | Ask a question |
| `/d` | Discussion listing |
| `/d/new` | Start a discussion |
| `/d/{slug}` | Discussion |
| `/c/{slug}` | Category |
| `/t/{slug}` | Tag |
| `/u/{username}` | Public profile |
| `/search` | Search results (`noindex`) |
| `/contact` | Contact form |
| `/login`, `/register`, `/logout` | Authentication |
| `/forgot-password`, `/reset-password` | Recovery |
| `/verify-email`, `/resend-verification` | Verification |
| `/settings/profile`, `/settings/api-tokens` | Account |
| `/notifications` | Member notifications |
| `/lang/{locale}` | Locale switch |
| `/sitemap.xml`, `/sitemaps/*.xml` | Sitemap index and children |
| `/robots.txt` | Robots policy |

Sub-actions hang off their parent (`/q/{slug}/vote`, `/q/{slug}/follow`, `/q/{slug}/report`, `/d/{slug}/follow`, …) and require POST with a CSRF token.

The full table is in [Routes](../reference/ROUTES.md).

## Canonical URL policy

A question has exactly one canonical route, `/q/{slug}`. `/questions` does not exist as a second indexable home page.

Pagination that changes content self-canonicalises: `?page=2`, `answers_page=N`, `comments_page=N` are preserved when greater than 1. Transient parameters (`created`, `voted`, `followed`, `reported`, `answer`, `commented`, `utm_*`) never enter a canonical, and page 1 omits `?page=1`.

## Indexability

Admin, authentication, account, notification, search and API routes are excluded from sitemaps and marked `noindex`. Only public content routes are indexable.

## Method handling

An unknown path answers 404 with a translated page. A known path with an unsupported method answers 405 and advertises the methods it accepts.
