What is 301 redirect? 301 redirect is when your website address changes, such as changing the domain name, website revision and so on, you want visitors or search engines to jump to the new address to visit the site, then you need to do 301 redirect. There are many ways to implement 301 redirection, this article mainly describes how PHP program to achieve 301 redirection.
implementing 301 redirect PHP code
$the _host = $_server[' http_host '); Tag gets the current domain name
$request _url = isset ($_server[' Request_uri ') "$_server[' Request_uri ']: '; Determine the back part of the address
if ($the _host!== ' www.bkjia.com')//No change of domain name address
{Header (' http/1.1 301 Moved permanently ');//Prompt Issued 301
Header (' Location: http://www.bkjia.com/'. $request _url); Add a new domain name address
}
?>
in which file to add 301 redirect Instructions
Added 301 redirect instructions in the. htaccess file, using "mod_rewrite" technology.
Example:
Rewriteengine on
Rewriterule ^ (. *) $ http://www.bkjia.com/$1 [R=301,l]
http://www.bkjia.com/PHPjc/371840.html www.bkjia.com true http://www.bkjia.com/PHPjc/371840.html techarticle What is 301 redirect? 301 redirect is when your website address changes, such as changing the domain name, website revision and so on, you want visitors or search engines to jump to the new address to visit ...