基于cos-html-cache实现WordPress页面纯静态化至KVDB_html/css_WEB-ITnose

jackie在sae上搭建了博客,起初使用了sae默认的wordpress 3.4.1,版本实在太低,作为php盲,只好忍了。

后来浏览网站时无心看到了 【WordPress SAE修改版】 WordPress on SAE 更新至 4.1,文章中提供了Wordpress 4.1 SAE改进的下载链接,以及升级方法,简单明了,于是Jackie的博客升级为了4.1版本。

前几天,Jackie在查阅资料时,不小心看到了 WordPress静态化插件SAE版, 于是不安分起来,参照文章中介绍的方法折腾了半天,终于搞定了静态化。

博客静态化的操作步骤

从 cos-html-cache插件官网下载插件,当前最新版本为2.7.4。将插件解压,并上传压缩包内的文件上传至wp-content/plugins/cos-html-cache内,目录内的文件布局如下:

common.js.phpcos-html-cache.phpcosbeta-zh_CN.mocosbeta-zh_CN.poreadme-chs.txtreadme.txt

登录后复制 在插件目录下增加index.php文件,内容如下

<?php define("SUMMETA",""); $kv = new SaeKV(); $kv->init(); $sitemap = $kv->get($_SERVER['SCRIPT_URI']."index.html"); if ($sitemap) {    header('Content-type:text/html; charset=utf-8');    echo $sitemap; }else{    echo fetchUrl($_SERVER['SCRIPT_URI']).SUMMETA; } function fetchUrl($url){    $ch=curl_init();    curl_setopt($ch, CURLOPT_AUTOREFERER,0);    curl_setopt($ch, CURLOPT_REFERER, 'staticindex');    curl_setopt($ch, CURLOPT_URL, $url);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    $ret=curl_exec($ch);    curl_close($ch);    if ($ret) {        return $ret;    }else{        return false;    }}?> 

登录后复制 在插件目录下增加static.php,内容如下

<?php define("SUMMETA",""); $kv = new SaeKV(); $kv->init(); $sitemap = $kv->get($_SERVER['SCRIPT_URI']); if ($sitemap) {    header('Content-type:text/html; charset=utf-8');    echo $sitemap; }else{    echo fetchUrl($_SERVER['SCRIPT_URI']).SUMMETA; } function fetchUrl($url){    $ch=curl_init();    curl_setopt($ch, CURLOPT_AUTOREFERER,0);    curl_setopt($ch, CURLOPT_REFERER, 'static');    curl_setopt($ch, CURLOPT_URL, $url);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    $ret=curl_exec($ch);    curl_close($ch);    if ($ret) {        return $ret;    }else{        return false;    }}?> 

登录后复制 修改SAE的config.yaml,增加rewrite规则,内容如下

name: app_nameversion: app_versionhandle:  - rewrite:  if ( %{REQ:REFERER} != "static" && %{REQUEST_URI} ~ "html$" ) goto "wp-content/plugins/cos-html-cache/static.php"  - rewrite:  if ( !is_dir() && !is_file()) goto "index.php?%{QUERY_STRING}"  - rewrite:  if ( path ~ "/(\s*)$" && %{REQ:REFERER} != "staticindex" ) goto "wp-content/plugins/cos-html-cache/index.php"  

登录后复制 修改cos-html-cache.php,使用SaeKV对象来保存、读取数据,如下是Patch

Index: cos-html-cache.php===================================================================--- cos-html-cache.php  (revision 27)+++ cos-html-cache.php  (revision 28)@@ -84,17 +84,21 @@    }    if ( !strstr( strtolower($Content), '

登录后复制

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/3117379.html

(0)
上一篇 2025年3月29日 13:37:12
下一篇 2025年3月29日 13:37:25

AD推荐 黄金广告位招租... 更多推荐

发表回复

登录后才能评论