1、通過buffer來實現
需要用file_put_contents ob_get_clean()等內置函數
ob_start (); include "filterpost.html"; $mtime = filemtime("./filterpost.html");//在這里可以判斷文件是否存在和過期,然后做緩存或者生成靜態文件操作 $pageCache = str_replace('submit2','login',ob_get_contents());//將緩存去中的內容替換 ob_end_clean(); echo $mtime; echo $pageCache;
2、通過$_SERVER['PATH_INFO']來實現
echo '<pre>'; print_r($_SERVER); preg_match('/^\/(\d+)\/(\d+)\.html/',$_SERVER['PATH_INFO'],$arr); print_r($arr);
3、通過Apache配置來實現
需要開啟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
如果服務器下不存在文件夾及其文件,那么就重寫定義到/detail.php
http://localhost/detail/1.html
如果沒有detail文件夾下的1.html 那么就重寫定義到./detail.php
4、通過Nginx配置來實現
在nginx.conf中配置
rewrite ^/detail/(\d+)\.html$ /detail.php?id=$1 last;
當然建議大家參考一些比較成熟的cms的方法,對于頁面數量不大的話,第一種方法還是不錯的。
【網站聲明】本站除付費源碼經過測試外,其他素材未做測試,不保證完整性,網站上部分源碼僅限學習交流,請勿用于商業用途。如損害你的權益請聯系客服QQ:2655101040 給予處理,謝謝支持。