修改为伪静态后,原来的含有index.php
的URL地址被隐藏了,如果不做301跳转,不利于SEO搜索引擎收录,参考修改404.php如下:
<?php
$error_url = '//'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$id = strstr($error_url, 'typecho/index.php/archives'); //截取以posts开始的字符串
if($id != "" ||$id != null){//判断是否不等于空或者null
$str = substr($id,26);
$id2 = substr($str,-1);
if($id2 != '/'){
header('HTTP/1.1 301 Moved Permanently'); //添加301状态码
header("location://".$_SERVER['HTTP_HOST']."/typecho/archives".$str.".html");//跳转页面
} //https://ntnas.top:82/typecho
elseif($id2 == '/'){
$nameid = substr($str,0,-1);
header('HTTP/1.1 301 Moved Permanently'); //添加301状态码
header("location://".$_SERVER['HTTP_HOST']."/typecho/archives".$nameid.".html");//跳转页面
}
}
?>
301跳转检测网站:
https://httpstatus.io/
参考链接:
https://cloud.tencent.com/developer/article/1609776?from=article.detail.1961797
https://baike.baidu.com/item/strstr/22372374)
https://baike.baidu.com/item/substr/10685875
版权属于:Mr.Tlyer
本文链接:https://ntnas.top:82/typecho/archives/245/
转载时请注明出处
最新回复