PHP 301 redirect location URI format PHP 301 redirect location URI format php php

PHP 301 redirect location URI format


You can also use:

header('Location: /', false, 301);

I assume you want to redirect to the 'homepage', that'd be / instead of ./


You must use an absolute URI according to the spec so something like the following should work for you:

// check if the server is secure or not to determine URL prefixif(isset($_SERVER['HTTPS']) and 'on' === $_SERVER['HTTPS']) {    $location = 'https://';} else {    $location = 'http://';}// get the servers base URL$location .= $_SERVER['SERVER_NAME'] . '/';// grab the current URI without a file name in it$location .= dirname($_SERVER['REQUEST_URI']) . '/';header('Location: ' . $location);exit();