WordPress博客首頁如何靜態

WordPress博客首頁如何靜態

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"); ?>

將文件上傳到網站根目錄后直接打開瀏覽器訪問該文件即可為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]

nginx下的解決方法

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

這樣首頁靜態就可以完全使用了!

更多wordpress相關技術文章,請訪問wordpress教程欄目進行學習!

? 版權聲明
THE END
喜歡就支持一下吧
點贊10 分享