php怎么做301重定向,掌握PHP设置301重定向方法

一,直接使用内置函数header

header( "Location: http://www.enenba.com", true, 301 );

二,使用HTTP/1.x声明301重定向

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

header( "Location: http://www.enenba.com" );

注意:http://www.enenba.com表示需要重定向的URL

示例:如果你需要将http://www.enenba.com/old.php 301重定向到http://www.enenba.com/new.php

方法:在old.php文件中添加如上301重定向两种方法中的任意一种

header( "Location: http://www.enenba.com/new.php",true,301 );

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

header( "Location: http://www.enenba.com/new.php" );

exit();

注意:location后的URL必须是完整的URL地址,如下:

NOT:www.enenba.com

YES:http://www.enenba.com

PHP内置header等函数资料

一,header 函数 送出 HTTP 协议的标头到浏览器,header参考资料

header ( string string [, bool replace [, int http_response_code]] )

例:PHP实现404未找到方法

header("HTTP/1.0 404 Not Found");

二,headers_list 函数 返回已发送(或准备发送)的响应标头的列表 headers_list参考资料

三,headers_sent 函数 检查标头是否已被发送以及在哪里被发送 headers_sent参考资料

学会使用PHP实现301永久性重定向,有利于搜索引擎优化。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值