合法優良搬家公司 價格透明,合約保障真安心 | 居家清潔請找 易祺清潔公司 |
Apache的rewrite 技術 |
房東:黑糖龍 發表時間:2007-04-28 |
Apache 特有的 rewrite 技術很好用,Vovo2000.Com 的 /gallery/ /vovo-gallery/ /phpbb2/ /linka/ ... 都已經徹底嵌入 rewrite。 Rewrite 很簡單的說,就是把類似 ==> /phpbb2/viewtopic.php?t=1388&start=0 動態網頁,轉成 ==> /phpbb2/viewtopic-1388-0.html 好處有: 1. URL 短一點,靜態網址的接受度較高。 2. Search Engine 比較吃的下去∼ 3. 靜態的網址會有比較好的 SE-BENCHMARK =========================================== =========================================== 在這裡舉 PHPBB2 2.0.3 的例子來說,一步一步來: 1. 把 Apache 的 Rewrite 打開(mod_rewrite) 2. 在 phpbb/include/page_header.php 的 // Generate logged in/logged out status 之前加入 代碼: ob_start(); function replace_for_mod_rewrite(&$s) { $urlin = array( "'(? "'(? "'(? "'(? "'(? "'(? "'(? "'(? "'(? "'(? ); $urlout = array( "viewforum-$1-$2-$3.html", "forum-$1.html", "forum-$1.html", "prev-topic-$1.html", "next-topic-$1.html", "viewtopic-$1-$2-$3-$4.html", "viewtopic-$1-$2.html", "viewtopic-$1.html", "viewpost-$1.html", "profile-$1.html" ); $s = preg_replace($urlin, $urlout, $s); $s = mb_ereg_replace( "viewtopic-([0-9]+).html&(.*)$", "viewtopic.php?t=\\1&\\2", $s); return $s; } 3. 在 phpbb/include/page_tail.php 代碼: 在下列?#123;式之後: $db->sql_close(); ?#91;入: $contents = ob_get_contents(); ob_end_clean(); echo replace_for_mod_rewrite($contents); global $dbg_starttime; 在下列?#123;式之後: ob_end_clean(); ?#91;入: echo replace_for_mod_rewrite($contents); global $dbg_starttime; 4. 接下來當然要建立 .htacce 的 rewrite rule 代碼: RewriteEngine On RewriteRule ^viewforum-([0-9a-zA-Z]+)-([0-9]+)-([0-9]+)\.html$ viewforum.php?f=$1&topicdays=$2&start=$3 RewriteRule ^forum-([0-9a-zA-Z]+)\.html$ viewforum.php?f=$1&mark=topic RewriteRule ^forum-([0-9a-zA-Z]+)\.html$ viewforum.php?f=$1 RewriteRule ^prev-topic-([0-9]+)\.html$ viewtopic.php?t=$1&view=previous RewriteRule ^next-topic-([0-9]+)\.html$ viewtopic.php?t=$1&view=next RewriteRule ^viewtopic-([0-9]+)-([0-9]+)\.html$ viewtopic.php?t=$1&start=$2 RewriteRule ^viewtopic-([0-9]+)-([0-9]+)-([a-zA-Z]*)-([0-9]+)\.html$ viewtopic.php?t=$1&postdays=$2&postorder=$3&start=$4 RewriteRule ^viewtopic-([0-9]+)\.html$ viewtopic.php?t=$1 RewriteRule ^viewpost-([0-9]+)\.html$ viewtopic.php?p=$1 RewriteRule ^viewtopic-([0-9]+)\.html&highlight=(.*)$ viewtopic.php?t=$1&highlight=$2 RewriteRule ^profile-([0-9]+)\.html$ profile.php?mode=viewprofile&u=$1 5. 測試∼ 當然 OK; 供各位參考,善用 Rewrite 讓您的動態網站更美觀、更一致、更方便被「吃」 。 |
|
廣利不動產-板橋在地生根最實在--新板特區指名度最高、值得您信賴的好房仲 完整房訊,房屋、店面熱門精選物件,廣利不動產 優質仲介,房屋租賃、買賣資訊透明,交易真安心! 廣利不動產-新板特區指名度最高、值得您信賴的好房仲 您的托付,廣利用心為您服務 |
姓名: | |||
佈告內容: | |||
其他選項: | |||
|