Home > CMS Tutorial > WordPress > body text

How to make WordPress blog homepage static

Release: 2019-07-20 15:58:56
Original
4123 people have browsed it

How to make WordPress blog homepage static

WordPress博客首页静态的方法如下:

首先新建一个php文件,文字可以自取,自己要记住,比如index-html.php,然后复制以下代码:

<?php
$baseCmsUrl = "https://www.ziyouwu.com";
$dmPageName = "index.php";
$stPageName = "index.html";
$tureStFile = dirname(__FILE__).&#39;/&#39;.$stPageName;
{
        $body = file_get_contents($baseCmsUrl.&#39;/&#39;.$dmPageName);
        $fp = fopen($tureStFile, &#39;w&#39;);
        fwrite($fp, $body);
        fclose($fp);
}
if(file_exists("index.html"))
 {
unlink("index.html");
 }
$baseCmsUrl = "https://www.ziyouwu.com";
$dmPageName = "index.php";
$stPageName = "index.html";
$tureStFile = dirname(__FILE__).&#39;/&#39;.$stPageName;
{
        $body = file_get_contents($baseCmsUrl.&#39;/&#39;.$dmPageName);
        $fp = fopen($tureStFile, &#39;w&#39;);
        fwrite($fp, $body);
        fclose($fp);
}
header("Location:$baseCmsUrl/index.html");
?>
Copy after login

将文件上传到网站根目录后直接打开浏览器访问该文件即可为wordpress首页生成html。

生成index.html文件后,我们要注意的是我们直接访问自己的域名和访问域名+index.html都会显示首页这样的会搜索引擎会认为你在制造重复页面,会给网站带来一定的负面影响,下面给出解决此问题的方法(访问index.html301转跳到/,即去除掉首页url中的index.html)

Apache下301跳转代码

RewriteEngine On 
RewriteBase / 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(php|html|htm)\ HTTP/ 
RewriteRule ^index\.(php|html|htm)$ http://www.ziyouwu.com/ [R=301,L]
Copy after login

nginx下的解决方法

location / {
     if (!-e $request_filename){
          rewrite ^/(.*)$ /index.html/$1 last;
     }
}
Copy after login

这样首页静态就可以完全使用了!

更多wordpress相关技术文章,请访问wordpress教程栏目进行学习!

The above is the detailed content of How to make WordPress blog homepage static. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!