学习NO.1 发表于 2016-1-11 00:08:25

wordpress加速:首页静态化超强提高wordpress速度

加速原理我们的wordpress网站属于动态网站(废话...),每次打开页面的时候,会有SQL的查询过程,如果页面文件过多,查询次数增加,便造成了网站访问速度慢。那么我们将页面静态化之后,便跳过了SQL的查询过程,直接将网页以html静态形式展现出来,那速度。。。能不快么?!实现方法1.新建一个页面(一定要注意编码格式utf-8),命名为index_html.php,将以下代码粘贴进去;代码备份地址:<!--?php <br ?--> $baseCmsUrl = "http://www.wenchenhk.com";
$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);
}

if(file_exists("index.html"))
{
unlink("index.html");
}
$baseCmsUrl = "http://www.wenchenhk.com";
$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.php页面上传到网站更目录;
3.访问http://你的网站/index_html.php页面,此时会在同目录下自动生成index.html文件了,这样每次访问我们的wordpress网站首页的时候,会自动跳转到生成的index.html页面上去。每次写完文章之后请手动访问http://你的网站/index._html.php页面
解除重复页面此时我们网站根目录下有三个index的文件,在访问网站时查询首页页面会有问题,搜索引擎会认为有重复页面,此时我们需要在.htacces文件中设置跳转到/,将以下代码粘贴到根目录下的.htacces文件中。RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^{3,9}\ /index\.(php|html|htm)\ HTTP/
RewriteRule ^index\.(php|html|htm)$ http://wenchenhk.com/


页: [1]
查看完整版本: wordpress加速:首页静态化超强提高wordpress速度