How to Make 301 Redirects with PHP?

Firstly, if we answer how to redirect in PHP,we can say that it is done with the header () function. As an example;

<?php

header('Location:http://phpexample.net')
// or time redirects
header('Refresh:2;Url=http://phpexample.net')

What is a 301 redirect, exactly? There is no difference from Normal Redirecting, we just redirecting with 301 code.

The 301 code indicates that the page we redirected here has been permanently moved. We can do this in 2 different way.

header("HTTP/1.1 301 Moved Permanently");
header("Location: http://phpexample.net");
exit

Or more simply;

header("Location: http://phpexample.net", true, 301);
exit;

 

Comments

There are no comments, make the firs comment