PHP 實(shí)現(xiàn)頁面靜態(tài)化的幾種方法
1、通過buffer來實(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']來實(shí)現(xiàn)
echo '<pre>'; print_r($_SERVER); preg_match('/^\/(\d+)\/(\d+)\.html/',$_SERVER['PATH_INFO'],$arr); print_r($arr);
3、通過Apache配置來實(shí)現(xiàn)
需要開啟rewrite重寫模塊
通過rewrite來配置vhost
RewriteEngine 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.php
4、通過Nginx配置來實(shí)現(xiàn)
在nginx.conf中配置
rewrite ^/detail/(\d+)\.html$ /detail.php?id=$1 last;
當(dāng)然建議大家參考一些比較成熟的cms的方法,對于頁面數(shù)量不大的話,第一種方法還是不錯(cuò)的。
- PHP實(shí)現(xiàn)頁面靜態(tài)化深入講解
- PHP頁面靜態(tài)化——純靜態(tài)與偽靜態(tài)用法詳解
- PHP單例模式數(shù)據(jù)庫連接類與頁面靜態(tài)化實(shí)現(xiàn)方法
- 實(shí)例講解PHP頁面靜態(tài)化
- 利用php的ob緩存機(jī)制實(shí)現(xiàn)頁面靜態(tài)化方法
- 詳解php實(shí)現(xiàn)頁面靜態(tài)化原理
- PHP實(shí)現(xiàn)頁面靜態(tài)化的超簡單方法
- PHP實(shí)現(xiàn)HTML頁面靜態(tài)化的方法
- PHP頁面靜態(tài)化的優(yōu)缺點(diǎn)與實(shí)現(xiàn)
相關(guān)文章
php字符串比較函數(shù)用法小結(jié)(strcmp,strcasecmp,strnatcmp及strnatcasecmp)
這篇文章主要介紹了php字符串比較函數(shù)用法,結(jié)合實(shí)例形式分析了php針對字符串的比較、排序等操作相關(guān)技巧與注意事項(xiàng),需要的朋友可以參考下2016-07-07DedeCMS 核心類TypeLink.class.php摘要筆記
DedeCMS 核心類TypeLink.class.php摘要筆記,學(xué)習(xí)php就是借鑒與分析,讓自己的掌握的更多。2010-04-04php下實(shí)現(xiàn)一個(gè)阿拉伯?dāng)?shù)字轉(zhuǎn)中文數(shù)字的函數(shù)
最近因需要,寫了個(gè)“阿拉伯?dāng)?shù)字轉(zhuǎn)中文數(shù)字的函數(shù)”。搜索了精華區(qū)只見到一個(gè)類似的。 感覺到我的算法不錯(cuò),所以貼出來共享一下2008-07-07php utf-8轉(zhuǎn)unicode的函數(shù)
php下我們想把uft-8,轉(zhuǎn)成unicode可以用下面的函數(shù)來實(shí)現(xiàn)2008-06-06