欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP 實(shí)現(xiàn)頁(yè)面靜態(tài)化的幾種方法

 更新時(shí)間:2017年07月23日 23:18:53   投稿:mdxy-dxy  
這篇文章主要介紹了PHP 實(shí)現(xiàn)頁(yè)面靜態(tài)化的幾種方法,需要的朋友可以參考下

1、通過(guò)buffer來(lái)實(shí)現(xiàn)

需要用file_put_contents ob_get_clean()等內(nèi)置函數(shù)

ob_start ();
include "filterpost.html";
$mtime = filemtime("./filterpost.html");//在這里可以判斷文件是否存在和過(guò)期,然后做緩存或者生成靜態(tài)文件操作
$pageCache = str_replace('submit2','login',ob_get_contents());//將緩存去中的內(nèi)容替換
ob_end_clean();
echo $mtime;
echo $pageCache;

2、通過(guò)$_SERVER['PATH_INFO']來(lái)實(shí)現(xiàn)

echo '<pre>';
print_r($_SERVER);
preg_match('/^\/(\d+)\/(\d+)\.html/',$_SERVER['PATH_INFO'],$arr);
print_r($arr);

3、通過(guò)Apache配置來(lái)實(shí)現(xiàn)

需要開(kāi)啟rewrite重寫(xiě)模塊
通過(guò)rewrite來(lái)配置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ù)器下不存在文件夾及其文件,那么就重寫(xiě)定義到/detail.php
http://localhost/detail/1.html
如果沒(méi)有detail文件夾下的1.html 那么就重寫(xiě)定義到./detail.php

4、通過(guò)Nginx配置來(lái)實(shí)現(xiàn)

 在nginx.conf中配置 

rewrite ^/detail/(\d+)\.html$ /detail.php?id=$1 last;

當(dāng)然建議大家參考一些比較成熟的cms的方法,對(duì)于頁(yè)面數(shù)量不大的話,第一種方法還是不錯(cuò)的。

相關(guān)文章

最新評(píng)論