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

How to implement 301 redirect jump in php

青灯夜游
Release: 2023-03-10 22:50:02
Original
3192 people have browsed it

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');
Copy after login

and then combined with

header('Location: https://www.php.cn');
Copy after login

.

I always feel like I can’t finish one sentence, and besides, HTTP/2 has been out for a long time, and I still wrote HTTP/1.1 to watch. It doesn’t feel good. Of course, it’s okay to write HTTP/2 or HTTP/1.0, but no matter what you write, there is always a feeling of unclear expression (for example, HTTP/ 1.1 is HTTP/2 during actual access - when accessing, it is still HTTP/2 when it should be HTTP/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 ]] )
Copy after login

This is easy to handle, in one sentence

header('Location: https://www.php.cn', true, 301);
Copy after login

It’s done, hahahahahahaha

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

header('Location: //www.php.cn', true, 301);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template