利用404.PHP错误文件实现论坛伪静态的PHP代码


 学习过SEO的朋友们都知道对于搜索引擎而言,收录HTML静态页面比收录PHP动态页面相对容易一些,会大大提高搜索引擎的收录量。对于不支持静态页面生成的论坛程序就需要使用伪静态了。但要实现伪静态需要你的虚拟主机支持REWRITE(URL重写),如果不支持REWRITE怎么办呢?不要紧,只要你的空间支持自定义404错误文件,我们就可以设定一个404.php错误文件来实现伪静态。下面我们就以Discuz7.2为例给出实现论坛伪静态的404.PHP文件源代码。
$url=$_SERVER['REQUEST_URI'];
if(preg_match(“/^\/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$/”,$url,$matcher)){
$tid= $matcher[1];
$extra = “page\%3D”.$matcher[3];
$page = $matcher[2];
include(“viewthread.php”);
}elseif(preg_match(“/^\/forum-([0-9]+)-([0-9]+)\.html$/”,$url,$matcher)){
$fid = $matcher[1];
$page = $matcher[2];
include(“forumdisplay.php”);
}elseif(preg_match(“/^\/space-(username|uid)-(.+)\.html$/”,$url,$matcher)){
$$matcher[1] = $matcher[2];
include(“space.php”);
}elseif(preg_match(“/^\/archiver\/((fid|tid)-[\w\-]+\.html)$/”,$url,$matcher)){
$_SERVER['QUERY_STRING'] = $matcher[1];
include(“archiver/index.php”);
}elseif(preg_match(“/^\/tag-(.+)\.html$/”,$url,$matcher)){
$name = $matcher[1];
include(“tag.php”);
}else{
header(“HTTP/1.0 404 Not Found”);
echo “File Not Found”;
}
?>

 

0 评论:

发表评论

请在本博发言,对你的言行负责,谢谢。