HTTP 301 Redirect using PHP
You can use PHP header() function to do redirect.
To do 301 redirect, use
1 2 |
header('Location: https://new-url/', true, 301); exit; |
For 302 redirect, use
1 2 |
header('Location: https://new-url/'); exit; |
If you need to redirect a site to new site keeping same URL structure, you can use
1 2 3 4 |
$newUrl = "https://NEW-URL-HERE" . $_SERVER['REQUEST_URI']; header("HTTP/1.1 301 Moved Permanently"); Header("Location: $newUrl"); exit; |