Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set up php301 Jump

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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 / /

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report