If you need your PHP script to redirect to a different website, you can send an HTTP header to do that.
Remember, header()
must be called before any actual output is sent, which includes not just HTML, but blank lines, etc.. as well.
If you need your PHP script to redirect to a different website, you can send an HTTP header to do that.
Remember, header()
must be called before any actual output is sent, which includes not just HTML, but blank lines, etc.. as well.
<?php
// Tell the web browser that the page has been moved to a new location
if (strpos(PHP_SAPI, 'cgi') === 0)
{
// If CGI interface between web server and PHP
header('Status: 301 Moved Permanently', true);
}
else
{
header('HTTP/1.1 301 Moved Permanently', true, 301);
}
// Execute the redirect
header("Location: https://www.example.com/foo.html");
// Don't process or spit out anything in the script after this
die();
That was a big help. Thank You so much!
Redirection in PHP can be done using the header() function. To setup a simple redirect, simply create an index.php file in the directory you wish to redirect from with the following content: < ?php header("Location: http://www.redirect.to.url.com/"); ?>
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.