Snippets

Make a Redirect in PHP

Posted by I. B. Gd Pramana A. Putra, 05 Aug 22, last updated 05 Aug 22

Redirection is a feature to redirect a user from the current location to the new location, as an example is to redirect you from https://kodekativ.co to https://id.kodekativ.co.

To implement a redirection feature in PHP, we can use header() function.

<?php
header("Location: https://id.kodekativ.co");
exit();
?>

If you want to tell browser that the redirection is permanent which is to redirect user a new website page from unused old page, you have to add more parameters in header() function:

<?php
// 301 Moved Permanently
header("Location: https://id.kodekativ.co", true, 301);
exit();
?>

Source: php.net - header function

I love sharing code snippets as most of the time, a quick code example is what we're looking for instead of long-written articles. If you think my code snippets are helpful and save you a lot of time, please consider buying me a cup of coffee :)

Support me via · paypal · buymeacoffee · ko-fi · trakteer
Contributed Snippets
Answer & Responses
    No comments yet

Wanna write a response?

You have to login before write a comment to this post.