Skip to content

Route Redirect

Dory Azar edited this page Nov 15, 2026 · 1 revision

Redirects: Route::redirect

Route::redirect($from, $to, $status = 302, $options = []) answers a GET by sending the visitor elsewhere, without a closure or a controller: an address that moved, a short address, the home page of a section. Since 2.19.0; keepQuery since 2.20.0.

Route::redirect('/catalog', '/books');                   // 302
Route::redirect('/old/books/{id}', '/books/{id}', 301);  // moved for good

With Claude

"Redirect /catalog to /books, and the old /old/books/{id} addresses to /books/{id} for good."

By hand

  1. In application/config/routing/web.php, before Route::run();:

        Route::redirect('/catalog', '/books');
  2. Run curl -s -i http://localhost:8080/catalog: it answers 302 Found with Location: http://localhost:8080/books.


How it works

  • {name} in the target takes the route variable of the same name (url-encoded); the query string never fills it (/old/books/2?x=1 goes to /books/2).
  • The target is a path of the site or a full https:// address.
  • The status is 301, 302 (default), 303, 307 or 308; anything else, or an empty target, stops with an error when web.php runs.
  • ['keepQuery' => true] (2.20.0) takes the query string along: /old?page=2 goes to /new?page=2. A #fragment of the target stays last.
Route::redirect('/old', '/new', 301, ['keepQuery' => true]);

Reference


Common mistakes

  • A redirect that depends on who asks, or on the data: that is a Route::action whose capability returns Web::redirect(...).
  • redirect() in a closure without return: redirect() only sends a Location header; code after it still runs. Route::redirect has no such problem.
  • Expecting the query string to fill {name}: only the route variables of $from do.

Related pages

Caligrafy: Describe it. Approve it. Ship it. Your idea turned into a complete app: every feature built once, for web pages, Vue apps, a REST API and AI agents, and online.

Start here

Why Caligrafy: the benefits, the measurements, and what it is not yet

  1. Quickstart with Claude: describe it, approve it, ship it

    or the Quickstart: the same three steps by hand, in 5 minutes

  2. How Caligrafy works: the ideas in 5 minutes
  3. Your first capability: build a feature, page included

Capabilities

Experiences

Data and people

  1. Models
  2. Relationships
  3. Queries: filters, paging, related rows
  4. Sign-in, users and tokens

Built-in features

Put it online

Build with AI

Reference

Clone this wiki locally