php偽靜態的實現方式

2022-08-18 10:09:11 字數 1944 閱讀 7054

1.根據$_server['path_info']來操作實現。

舉個列子比如你的**的位址是

你echo $_server['path_info'] 出來的結果就會是 /look-id-1.shtml 看到這個我想大家可能已經明白了。

完整的demo

index.php

index.php

$conn=mysql_connect("localhost","root","root")or dir("連線失敗");

mysql_select_db("tb_demo",$conn

);$sql="select * from news";

$res=mysql_query($sql

);header("content-type:text/html;charset=utf-8");

echo "";

echo "新增新聞

";echo "";

echo "id

標題修改新聞

";while($row=mysql_fetch_assoc($res

))修改頁面";}

//上面的紅色的位址本來該是show_news.php?act=look&id=

echo "";

//關閉資源

mysql_free_result($res

);mysql_close($conn);

show_new.php頁面

show_new.php

header("content-type:text/html;charset=utf-8");

$conn=mysql_connect("localhost","root","root");

mysql_select_db("tb_demo",$conn

);mysql_query("set names utf8");

$pa = $_server['path_info'];

//$pa 列印出來的值是 /look-id-1.html

//通過正規表示式匹配獲取的url位址

if(preg_match('/^\/(look)-(id)-([\d])\.shtml$/',$pa,$arr

))else

mysql_close($conn);

看到上面的這個我想大家肯定懂了吧   其實這種方式用的不多的下面的給大家說第二種方法了啊

2.根據配置.htaccess來實現。

先說下.htaccess檔案怎麼建立吧,在**根目錄下建立個記事本然後雙擊開啟點選另存為 檔名寫成

.htaccess ,儲存型別選擇所有檔案,編碼選擇utf-8的編碼好的這是你就在目錄看到這個.htaccess檔案了

首先在apache 開啟mod_rewrite.so,allowoverride none  這裡有兩處 替換為 allowoverride all

比如href 位址寫成 one_new-id-1.shtml //這個意思是one_new.php?id=1

這裡的.htaccess 就可以這麼寫了

#

寫你的rewrite規則

rewriteengine on

#可以配置多個規則,匹配的順序是從上到下

rewriterule one_new-id-(\d+)\.shtml$ one_new.php?id=$1 //

這裡的$1 代表的是第乙個引數啊

rewriterule abc_id(\d+)\.html$ error.php

#設定404錯誤

#errordocument 404 /error.php

你在one_new.php 頁面echo $_get['id'] 肯定會輸出 id的值了

PHP實現偽靜態化頁面的具體實現方式

大家也許對php偽靜態頁面還比較陌生,今天我們就向大家具體講解php實現偽靜態化頁面的具體 讓大家對對php偽靜態有乙個更加深入的了解。php實現偽靜態化頁面方法一 在你的程式初始化時使用如下 1 2 3 4 5 6 7 8 9 10 11 12 php2html fileurl server re...

PHP偽靜態簡單實現(八)

class falsestatichtml 如果time大於的話直接給訪問者看html文件就是了 並停止程式的執行 然後跳轉到靜態頁面裡去 gotohtml string filename null,string suffix html string path null,uint time 60 r...

偽靜態的實現

所謂的偽靜態頁面,就是指的url重寫,在asp.net中實現非常簡單 首先你要在你的專案裡引用兩個dll actionlessform.dll urlrewriter.dll 真正實現重寫的是 urlrewriter.dll 但是如果你要實現分頁,那麼必須使用這個actionlessform dll...