Typecho生成静态首页index.html文件
时间:2年前 游览量:701 标签: nbsp quot html php contents
在挨踢路看到的教程,不仅仅适用于Typecho,wordpress也是可以通用。
教程
在网站根目录新建文件f5.php
然后里面写入下面的代码。
<?php $nowtime=time(); $pastsec = $nowtime - $_GET["t"]; if($pastsec<600) { exit; //10分钟更新一次,时间可以自己调整 } ob_start(); //打开缓冲区 include("index.php"); $content = ob_get_contents(); //得到缓冲区的内容 $content .= "\n<script language=javascript src=\"f5.php?t=".$nowtime."\"></script>"; //加上调用更新程序的代码 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
就说明生成成功了,然后查看首页代码,末尾出现“<script language=javascript>......
”之类的字眼,说明你访问的就是index.html
的页面,到此,完工!
补充
我的index.html
生成成功了,但是每次访问末尾都没有出现“<script language=javascript>......
”之类的字眼,这说明程序默认访问index.php比index.html权限高。需要手动调整下:
如果你用的是宝塔
按照下图,将index.html
调整到index.php
上边保存即可。
如果你用的是cPanel
在.htaccess
中添加DirectoryIndex index.html index.php index.htm
保存即可