Use redirect()->away() to send users to external third-party URLs without URL sanitization or local route resolution.
Standard redirect($url) in Laravel validates URLs against the application's root URL and headers. When redirecting users to external payment gateways, OAuth providers, or affiliate partners (such as Stripe Checkout or PayPal), standard redirects can sometimes conflict with security headers or internal URL parsing.
redirect()->away() creates a clean redirect response specifically intended for external destinations.
Basic External Redirect
use Illuminate\Http\RedirectResponse;
public function redirectToGateway(): RedirectResponse
{
$checkoutUrl = 'https://checkout.stripe.com/c/pay/cs_live_...';
// Generates a pure 302 redirect directly to the external domain
return redirect()->away($checkoutUrl);
}
Custom Status Codes and Headers
return redirect()->away('https://partner.example.com', 301, [
'Referrer-Policy' => 'no-referrer',
]);
Summary
- Specifically designed for off-site URLs (OAuth flows, payment gateways, external documentation).
- Bypasses internal URL validation and local prefix scoping.
- Supports custom HTTP redirect status codes and headers.
Tags:
Laravel Routing HTTP Controllers