Typecho生成静态首页index.html文件
作者:佚名
来源:爱好者
时间:2019-11-02
在挨踢路看到的教程,不仅仅适用于Typecho,wordpress也是可以通用。
教程
在网站根目录新建文件f5.php然后里面写入下面的代码。
$nowtime=time();
$pastsec = $nowtime - $_GET["t"];
if($pastsec<600)
{
exit; //10分钟更新一次,时间可以自己调整
}
ob_start(); //打开缓冲区
include("index.php");
$content = ob_get_contents(); //得到缓冲区的内容
$content .= "\n"; //加上调用更新程序的代码
file_put_contents("index.html",$content);
if (!function_exists("file_put_contents"))
{
function file_put_contents($fn,$fs)
{
$fp=fopen($fn,"w+");
fputs($fp,$fs);
fclose($fp);
}
}
?>
然后浏览器打开你的域名/f5.php,打开后你将看到的还是你的首页,刷新你的网站根目录,看到一个index.html就说明生成成功了,然后查看首页代码,末尾出现“
补充
我的index.html生成成功了,但是每次访问末尾都没有出现“
如果你用的是宝塔
按照下图,将index.html调整到index.php上边保存即可。
宝塔默认文档修改.jpg
如果你用的是cPanel
在.htaccess中添加DirectoryIndex index.html index.php index.htm保存即可
cPanel默认文档修改.jpg
分享到: