Redirect

The Request::redirect() method works by sending an HTTP Location header to the browser. This header instructs the client to immediately navigate to a new URL. Redirects are a core part of HTTP and are commonly used to guide users after actions such as signing in, submitting forms, or accessing restricted content.

HTTP Status Codes Used for Redirects

Redirects typically rely on 3xx status codes. The most commonly used are:

  • 302 Found – The most common redirect. It tells the browser to temporarily visit another URL.
  • 301 Moved Permanently – Indicates that the resource has permanently moved to a new URL.
  • 307 Temporary Redirect – Similar to 302, but preserves the request method.
  • 308 Permanent Redirect – Same as 301, but preserves the request method.

What Prisma PHP Does Internally

When you call: Request::redirect('/home'), Prisma PHP automatically:

  1. Sends an HTTP status code (usually 302).
  2. Sends a Location header with the target URL.
  3. Stops PHP execution immediately to prevent further output.
  4. Allows the browser to read the header and navigate to the new route.
HTTP/1.1 302 Found
Location: /home

    

The browser receives this response and instantly loads /home. This guarantees a smooth user experience and a seamless navigation flow inside your application.

Why Redirects Are Important

  • They prevent duplicate form submissions.
  • They keep URLs clean after POST requests.
  • They guide users after authentication.
  • They secure private pages by redirecting unauthorized users.