Redirect Tag
Anytime this tag is rendered — whether in a template, partial, or content, Statamic will redirect the visitor to the specified URL.
Redirecting to URLs
Let's redirect visitors to the homepage if they're not logged in.
{{ if ! logged_in }} {{ redirect to="/" }}{{ /if }}
@if (! $logged_in) <s:redirect to="/" />@endif
How about RickRolling visitors if it's April Fool's Day?
{{ if (now|format:m-d) == "04-01" }} {{ redirect to="https://www.youtube.com/watch?v=dQw4w9WgXcQ" }}{{ /if }}
@if (Statamic::modify($now)->format('m-d')->fetch() == '04-01') <s:redirect to="https://www.youtube.com/watch?v=dQw4w9WgXcQ" />@endif
Named Routes
You may redirect to named routes with the route
parameter. Anything else will be passed along as route parameters.
Route::get('products/{product}/{size}', fn($product, $size) => ...) ->name('products.show');
{{ redirect route="products.show" product="socks" size="large" }}// /products/socks/large
<s:redirect route="products.show" product="socks" size="large"/>
Parameters
url
string
Destination URL
to
string
Alias of url
route
string
Instead of entering a URL, you can specify a route name. Any other parameters will be passed along as route parameters.
response
integer
The HTTP response code to use. Default: 302
(temporary).
Docs Feedback
Submit improvements, related content, or suggestions through Github.
Betterify this page