php 页面重定向_如何在PHP中使用HTTP 301重定向页面

php 页面重定向

HTTP 301 Redirect is an SEO friendly way to redirect readers to a page’s new location. There are a lot of benefits of using HTTP 301 Redirect. These benefits can be found in the htaccess method post. htaccess or PHP can be both used for sending 301 redirects. The htaccess method can be found in How to Redirect Old Domain to New Domain Using htaccess Redirect. This post discusses the method that use php to generate the HTTP 301 Redirect.

HTTP 301 重定向是SEO友好的方法,用于将读者重定向到页面的新位置。 使用HTTP 301重定向有很多好处。 这些好处可以在htaccess方法中找到。 htaccess或PHP均可用于发送301重定向。 htaccess方法可以在如何使用htaccess重定向将旧域重定向到新域中找到 。 这篇文章讨论了使用php生成HTTP 301重定向的方法。

As an example, we will redirect a page to https://www.systutorials.com in PHP.

例如,我们将页面重定向到PHP中的https://www.systutorials.com

The code:

代码:

<?php
// Permanent 301 redirection
header("HTTP/1.1 301 Moved Permanently");
header("Location:https://www.systutorials.com/");
exit();
?>

Or simpler

或更简单

<?php
header("Location: https://www.systutorials.com/", true, 301);
exit();
?>

The header("HTTP/1.1 301") part must be used before the location part, otherwise PHP will automatically set the status code to HTTP/1.1 302 Found.

必须在位置部分之前使用header(“ HTTP / 1.1 301”)部分,否则PHP将自动将状态代码设置为HTTP / 1.1 302 Found。

翻译自: https://www.systutorials.com/permanent-redirect-with-http-301-in-php/

php 页面重定向

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值