PHP 301 URL Redirect URL

Is this the correct URI for header('Location: ') , in particular ./ ?

 header ('HTTP/1.1 301 Moved Permanently'); header ('Location: ./'); 

Thanks.

+7
source share
2 answers

You must use an absolute URI according to the specification , so the following should work for you:

 // check if the server is secure or not to determine URL prefix if(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(); 
+5
source

You can also use:

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

I assume that you want to redirect to the "home page", which would be / instead. /

+7
source

All Articles