新聞中心
這篇文章給大家介紹在PHP中實(shí)現(xiàn)頁(yè)面靜態(tài)化的方法有哪些,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
1、通過buffer來(lái)實(shí)現(xiàn)
需要用file_put_contents ob_get_clean()等內(nèi)置函數(shù)
ob_start (); include "filterpost.html"; $mtime = filemtime("./filterpost.html");//在這里可以判斷文件是否存在和過期,然后做緩存或者生成靜態(tài)文件操作 $pageCache = str_replace('submit2','login',ob_get_contents());//將緩存去中的內(nèi)容替換 ob_end_clean(); echo $mtime; echo $pageCache;
2、通過$_SERVER['PATH_INFO']來(lái)實(shí)現(xiàn)
echo ''; print_r($_SERVER); preg_match('/^\/(\d+)\/(\d+)\.html/',$_SERVER['PATH_INFO'],$arr); print_r($arr);3、通過Apache配置來(lái)實(shí)現(xiàn)
需要開啟rewrite重寫模塊
通過rewrite來(lái)配置vhostRewriteEngine on RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteRule ^/detail/([0-9]*).html$ /detail.php?id=$1如果服務(wù)器下不存在文件夾及其文件,那么就重寫定義到/detail.php
http://localhost/detail/1.html
如果沒有detail文件夾下的1.html 那么就重寫定義到./detail.php4、通過Nginx配置來(lái)實(shí)現(xiàn)
在nginx.conf中配置
rewrite ^/detail/(\d+)\.html$ /detail.php?id=$1 last;關(guān)于在PHP中實(shí)現(xiàn)頁(yè)面靜態(tài)化的方法有哪些就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
當(dāng)前題目:在PHP中實(shí)現(xiàn)頁(yè)面靜態(tài)化的方法有哪些-創(chuàng)新互聯(lián)
分享鏈接:http://www.ef60e0e.cn/article/gcjde.html