View as Markdown:
Actions Reference
This is the complete reference for all actions provided by the Acorn package. Actions modify the outgoing HTTP response through the ResponseCollector.
Redirect#Copied!
Redirect the request to a different URL.
| Property | Value |
|---|---|
| Type | redirect |
| Class | MilliRulesAcornPackagesAcornActionsRedirect |
| Arguments | url (string), status (int, default: 302) |
| Placeholder support | Yes — {route.parameters.*}, {route.name}, etc. |
Builder Syntax#Copied!
1->redirect(string $url, int $status = 302)
Behavior#Copied!
- A redirect replaces the entire original response. The controller's response body is discarded.
- If multiple
redirectactions fire, the last one wins — each call tosetRedirect()overwrites the previous. - Headers set by
setHeaderactions are applied to the redirect response as well. - The redirect uses
IlluminateHttpRedirectResponseinternally.
Examples#Copied!
Simple redirect with a permanent status:
1Rules::create('legacy-docs-redirect')
2 ->when()
3 ->routeName('docs.legacy')
4 ->then()
5 ->redirect('/docs', 301)
6 ->register();
Temporary redirect (default 302):
1Rules::create('maintenance-redirect')
2 ->when()
3 ->routeName('docs.maintenance')
4 ->then()
5 ->redirect('/maintenance')
6 ->register();
Dynamic redirect using placeholders:
1Rules::create('product-redirect')
2 ->when()
3 ->routeName('docs.old-product')
4 ->then()
5 ->redirect('/docs/{route.parameters.product}/latest', 301)
6 ->register();
Warning: An empty URL (empty string) is silently ignored — no redirect occurs. Always ensure the URL argument resolves to a non-empty value.
Array Syntax#Copied!
1['type' => 'redirect', 'url' => '/docs', 'status' => 301]
2['type' => 'redirect', 'url' => '/docs/{route.parameters.product}']
Set Header#Copied!
Add an HTTP response header.
| Property | Value |
|---|---|
| Type | set_header |
| Class | MilliRulesAcornPackagesAcornActionsSetHeader |
| Arguments | name (string), value (string) |
| Placeholder support | Yes — {route.parameters.*}, {route.name}, etc. |
Builder Syntax#Copied!
1->setHeader(string $name, string $value)
Behavior#Copied!
- Headers are additive — multiple
setHeadercalls with different header names all apply. - For the same header name, the last value wins —
addHeader()overwrites previous values for a given key. - Headers are applied to both normal responses and redirect responses.
- An empty header name is silently ignored.
Examples#Copied!
Single header:
1Rules::create('nosniff-header')
2 ->when()
3 ->routeName('docs.*', 'LIKE')
4 ->then()
5 ->setHeader('X-Content-Type-Options', 'nosniff')
6 ->register();
Multiple headers in one rule:
1Rules::create('security-headers')
2 ->when()
3 ->routeName('docs.*', 'LIKE')
4 ->then()
5 ->setHeader('X-Content-Type-Options', 'nosniff')
6 ->setHeader('X-Frame-Options', 'DENY')
7 ->setHeader('X-XSS-Protection', '1; mode=block')
8 ->register();
Dynamic value using placeholders:
1Rules::create('product-header')
2 ->when()
3 ->routeParameter('product')
4 ->then()
5 ->setHeader('X-Product', '{route.parameters.product}')
6 ->register();
Cache control headers:
1Rules::create('cache-docs')
2 ->when()
3 ->routeName('docs.show')
4 ->then()
5 ->setHeader('Cache-Control', 'public, max-age=3600')
6 ->setHeader('Vary', 'Accept-Encoding')
7 ->register();
Array Syntax#Copied!
1['type' => 'set_header', 'name' => 'X-Custom', 'value' => 'hello']
2['type' => 'set_header', 'name' => 'X-Product', 'value' => '{route.parameters.product}']
Tip: Use
setHeader for standard HTTP headers like Cache-Control, Vary, security headers, and custom X-* headers. The header name and value are passed directly to SymfonyComponentHttpFoundationResponseHeaderBag::set().
Acorn MilliRules Documentation