Home>Article>Backend Development> How to implement 301 redirect jump in php

How to implement 301 redirect jump in php

青灯夜游
青灯夜游 Original
2021-06-28 18:24:20 3085browse

Method: 1. Use "header('HTTP/1.1 301 Moved Permanently'); header('Location:URL address');" statement to jump; 2. Use "header('Location:URL' ,true,301)" statement jump.

How to implement 301 redirect jump in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php implements 301 reload Directional jump

After searching around the Internet, it was all done using

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

and then combined with

header('Location: //m.sbmmt.com');

.

I always feel like I can’t finish one sentence, and besides,HTTP/2has been out for a long time, and I still wroteHTTP/1.1to watch. It doesn’t feel good. Of course, it’s okay to writeHTTP/2orHTTP/1.0, but no matter what you write, there is always a feeling of unclear expression (for example,HTTP/ 1.1isHTTP/2during actual access - when accessing, it is stillHTTP/2when it should beHTTP/2. There will be no problem and no confusion. ChangeHTTP/1.1)

Go to php.net and search again, and find that the Header can be used like this

header ( string $header [, bool $replace = TRUE [, int $http_response_code ]] )

This is easy to handle, in one sentence

header('Location: //m.sbmmt.com', true, 301);

It’s done, hahahahahahaha

One more thing, if you want to adaptHTTPS/HTTP, this is enough:

header('Location: //m.sbmmt.com', true, 301);

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to implement 301 redirect jump in php. For more information, please follow other related articles on the PHP Chinese website!

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