wordpress,php加速:首页静态化超强提高速度 生成html

wordpress,php加速:首页静态化超强提高速度 生成html

1、新建一个名为index_html.php的文件并加入一下代码:

<?php
if(file_exists(“index.html”))
{
unlink(“index.html”);
}
$baseCmsUrl = “http://www.tte.cc”;
$dmPageName = “index.php”;
$stPageName = “index.html”;
$tureStFile = dirname(__FILE__).’/’.$stPageName;
{
$body = file_get_contents($baseCmsUrl.’/’.$dmPageName);
$fp = fopen($tureStFile, ‘w’);
fwrite($fp, $body);
fclose($fp);
}
header(“Location:$baseCmsUrl/index.html”);
?>
2、生成index.html文件后,我们要注意的是我们直接访问自己的域名和访问域名+index.html都会显示首页这样的会搜索引擎会认为你在制造重复页面,会给网站带来一定的负面影响,下面小V给出解决此问题的方法(访问index.html301转跳到/,即去除掉首页url中的index.html):将文件上传到网站根目录后直接打开浏览器访问该文件即可为wordpress首页生成html。

apache下的解决方法:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(php|html|htm)\ HTTP/
RewriteRule ^index\.(php|html|htm)$ http://www.tte.cc/ [R=301,L]

nginx下的解决方法
location / {
if (!-e $request_filename){
rewrite ^/(.*)$ /index.html/$1 last;
}
}

给WordPress部署CDN加速和Cookie-Free Domains

给WordPress部署CDN加速和Cookie-Free Domains,雅虎的网页前端优化23条里其中两条是:使用内容分发网络(Use a Content Delivery Network (CDN))使用无cookie的域(Use Cookie-Free Domains for Components)

第一步(方法一):

这两点对使用WordPress开发的网站来说可能难于实现,其实我们只需要在 wp-congif.php 里增加两个参数就可以搞定。打开 wp-config.php ,增加下面的内容:

1
2
define("WP_CONTENT_URL", "http://content.ln.la/wp-content");
define("COOKIE_DOMAIN", www.ln.la);

我的目的是把 wp-content 目录里的内容都通过 content.ln.la这个域名来加载,这点并不需要使用真正的 CDN 服务来实现,只需要把content.ln.la 也指向主域名的根目录就可以。

另外我通过 COOKIE_DOMAIN 常量来限制 cookie 的作用域,因此当浏览器加载 content.ln.la 里的内容时,request header里不会带有主域的 cookie,节约了传输带宽,达到提高加载速度的目的。

继续阅读给WordPress部署CDN加速和Cookie-Free Domains