Get the App
SLTechnology News&Howtos  ›  Development  › 

How to set up php301 Jump

Shulou Source: shulou.com Published: 2022-06-03 10:38:04 10月02日 Update

Php301 jump how to set up, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

The setting method of php301 jump: 1. Send 301 status code using header, such as "header ('HTTP/1.1 301 Moved Permanently');"; 2, use "header (' Location: xxx'...)" Just jump.

This article operating environment: Windows7 system, PHP7.1 version, Dell G3 computer

How to set up php301 Jump?

Php implements 301 redirect redirect instance code

This article mainly introduces php to achieve 301 redirect jump, through the example code to let you better understand the method of redirection, partners in need can refer to the following

In php, the implementation of 301 redirection is very simple. We simply send the 301 status code using header, and then jump with header. The effect is the same as that of apache,iis,nginx.

One: this method is more recommended because it can transfer all the original url of http://www.jb51.net to the new address of http://jb51.net.

The code is as follows:

Two: 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 301Moved Permanently"); Header ("Location: / index.php");} elseif ($HTTP_HOST== "jbzj.com") {header ("HTTP/1.1 301Moved Permanently"); Header ("Location: www.jbzj.com");} else {Header ("Location: / 404.htm");}? >

Other jump methods are attached.

The code is as follows:

/ / define code header ('Content-Type:text/html;charset=utf-8'); / / Atomheader ('Content-type: application/atom+xml'); / / CSSheader (' Content-type: text/css'); / / Javascriptheader ('Content-type: text/javascript'); / / JPEG Imageheader (' Content-type: image/jpeg'); / / JSONheader ('Content-type: application/json'); / / PDFheader (' Content-type: application/pdf'); / / RSSheader ('Content-Type: application/rss+xml) Charset=ISO-8859-1'); / / Text (Plain) header ('Content-type: text/plain'); / / XMLheader (' Content-type: text/xml'); / / okheader ('HTTP/1.1 200 OK'); / / set a 404 header: header (' HTTP/1.1 404 Not Found'); / / set the address to be permanently redirected header ('HTTP/1.1 301 Moved Permanently') / / go to a new address header ('Location: http://www.example.org/');// file delay redirection: header (' Refresh: 10; url= http://www.example.org/');print 'You will be redirected in 10 seconds';//). Of course, you can also use the HTML syntax to implement / /

Tags: Code content files methods addresses documents help examples guys buddies effects novices browsers status types browsing clarity previous generation animation for this Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft NVidia Apple Shulou Information macOS