Home  >  Article  >  Backend Development  >  PHP code to implement 301 redirect_PHP tutorial

PHP code to implement 301 redirect_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:22:431502browse

The code for PHP to implement 301 redirect

The code for PHP to implement 301 redirect is as follows:

Header('HTTP/1.1 301 Moved Permanently');//Send 301 header

Header('Location: http://www.'.$strDomain.$request_uri);//Jump to my new domain name address

I wrote the 301 code using the 301.inc.php file and quoted it in the headers of other files

//----------------------------------

 //301 Redirect

$strDomain="chinawecan.com";

$the_host = $_SERVER['HTTP_HOST']; //Get the domain name entered

 $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';//Judge the back part of the address

 if($the_host !== 'www.'.$strDomain) //This is the previous domain name I want

 {

/* "!==" means not exactly equal. You can also use "!=" not equal. In this way, you can replace the previous domain name with

Including gcxirang.com, www.gcxirang.com and the new domain name gcidc.net are all redirected to www.gcidc.net*/

Header('HTTP/1.1 301 Moved Permanently');//Send 301 header

Header('Location: http://www.'.$strDomain.$request_uri);//Jump to my new domain name address

 }

//----------------------------------

 ?>

Quote as follows:

//----------------------------------

 //301 Redirect

include('include/301.inc.php');

 ?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/847202.htmlTechArticleThe code for PHP to implement 301 redirection The code for PHP to implement 301 redirection is as follows: header('HTTP/1.1 301 Moved Permanently');//Issue 301 header('Location: http://www.'.$strDomain.$request...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn