In PHP 301 REDIRECT implementation is very simple, we simply use the header to send 301 status code, and then use header to jump, the effect and Apache,iis,nginx are the same effect oh.
One: This method is more recommended because it can transfer all the URLs of Http://www.jb51.net to Http://jb51.net's new address.
The code is as follows
<?php
$the _host = $_server[' http_host '];
$request _uri = isset ($_server[' Request_uri '))? $_server[' Request_uri ']: ';
if ($the _host = = ' Www.jb51.net ')
{
header (' http/1.1 moved Permanently ');
Header (' location:http://jb51.net '. $request _uri);/
}
?>
Second: Single-page multi-station Php301 redirection code , www.jb51.net and jb51.net 301 to index.php,jbzj.com 301 to Www.jbzj.com , otherwise go to error page
The code is as follows
if ($HTTP _host== "www.jb51.net") or ($HTTP _host== "jb51.net"))
{
header ("http/1.1-Moved Permanently");
Header ("Location:/index.php");
}
ElseIf ($HTTP _host== "jbzj.com")
{
header ("http/1.1-Moved Permanently");
Header ("Location:www.jbzj.com");
}
else
{
Header ("Location:/404.htm");
>
Attach other ways to jump
The code is as follows
Defines the encoding header (' content-type:text/html;charset=utf-8 ');
Atom header (' Content-type:application/atom+xml ');
CSS header (' content-type:text/css ');
Javascript header (' Content-type:text/javascript ');
JPEG Image Header (' content-type:image/jpeg ');
JSON header (' Content-type:application/json ');
PDF header (' content-type:application/pdf ');
RSS header (' Content-type:application/rss+xml charset=iso-8859-1 ');
Text (Plain) header (' Content-type:text/plain ');
XML header (' Content-type:text/xml ');
OK header (' http/1.1 ok ');
Set a 404 Header: Header (' http/1.1 404 Not Found ');
Set address to be permanently redirected header (' http/1.1 moved Permanently ');
Go to a new address header (' location:http://www.example.org/');
File Delay Steering: Header (' refresh:10 url=http://www.example.org/');
print ' You'll be redirected in seconds '; Of course, you can also use HTML syntax to implement//<meta http-equiv= "Refresh" content= "10;http://www.example.org//>//override x-powered-by
: Php:header (' x-powered-by:php/4.4.0 '); Header (' x-powered-by:brain/0.6b ');
Document Language header (' content-language:en '); Tells the browser last modified $time = time ()-60; or Filemtime ($FN), etc header (' last-modified: '. Gmdate (' d, D M Y h:i:s ', $time). '
GMT ');
Tells the browser that the contents of the document have not changed header (' http/1.1 304 not Modified ');
Set the content Length header (' content-length:1234 ');
Set to a download type header (' Content-type:application/octet-stream ');
Header (' content-disposition:attachment; filename= "Example.zip");
Header (' content-transfer-encoding:binary ');
Load the file to Send:readfile (' example.zip ');
Disables the cache header for the current document (' Cache-control:no-cache, No-store, max-age=0, Must-revalidate '); Header (' Expires:mon, June 1997 05:00:00 GMT ');
Date in the past header (' Pragma:no-cache ');
Set Content Type: Header (' content-type:text/html charset=iso-8859-1 ');
Header (' content-type:text/html; Charset=utf-8 '); Header (' Content-type:text/plain '); Plain Text Format header (' Content-type:image/jpeg '); jpg*** header (' Content-type:application/zip '); Zip file header (' Content-type:application/pdf '); PDF file Header (' Content-tYpe:audio/mpeg '); Audio file header (' Content-type:application/x-shockw**e-flash ');
Flash animation//Display Login Dialog header (' http/1.1 401 Unauthorized ');
Header (' Www-authenticate:basic realm= "top Secret");
print ' Text that'll be displayed if the user hits cancel or '; print ' enters wrong login data ';
Jump to pay attention to the following points to help solve some novice frequently encountered problems
1, location and ":" No space between the number, or there will be errors.
2, can not have any output before using header.
3, after the header of the PHP code will also be executed.
Above is, the PHP 301 redirect to the data collation, hope to help the development of PHP students.