wordpress博客首頁靜態的方法如下:
首先新建一個php文件,文字可以自取,自己要記住,比如index-html.php,然后復制以下代碼:
<?php $baseCmsUrl = "https://www.ziyouwu.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 = "https://www.ziyouwu.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"); ?>
將文件上傳到網站根目錄后直接打開瀏覽器訪問該文件即可為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