简体   繁体   English

PHP 中的 301 重定向

[英]301 Redirect In PHP

I keep hearing about a 301 redirect.我不断听到有关 301 重定向的消息。 Is it the same as doing this?:和这样做一样吗?:

<?php
  header("Location: https://www.example.com/");
  exit();
?>

What is the difference between doing this or redirecting in a different way.这样做或以不同的方式重定向有什么区别。 Thanks in advance.提前致谢。

According to the documentation ( https://www.php.net/manual/en/function.header.php ) header('Location: ...') returns with a status code of 302 which means 'moved temporarily'.根据文档( https://www.php.net/manual/en/function.header.php )标头('位置:意味着'返回临时状态码' 302 ...') If you would like to tell the browser that this is a permanent redirect, use a 301 status code, like this:如果您想告诉浏览器这是一个永久重定向,请使用 301 状态代码,如下所示:

header("Location: https://www.example.com/", true, 301);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM