Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Redirect

An HTTP redirect instructs the client to navigate to a different URL. PHP performs redirects by sending a Location header with an appropriate HTTP status code: 301 for permanent redirect, 302 for temporary, or 303 for ‘see other’.

After sending the redirect header, execution should stop immediately with exit to prevent further output being sent to the client.

<?php

    // Temporary redirect
    header('Location: /new-page');
    exit;
    
    // Permanent redirect
    header('Location: https://example.com/new-page', true, 301);
    exit;

?>

Documentation

See Also