linux apache 偽靜態詳細說明
一 開啟 apache 的設定檔 httpd.conf 。
二 將#loadmodule rewrite_module modules/mod_rewrite前面的#去掉
三 在 httpd.conf中添加:
<ifmodule mod_rewrite.c>
rewriteengine on
#rewritecond %{env:script_url} (?:index|dispbbs)[-0-9]+.html
rewriterule ^(.*?(?:index|dispbbs))-([-0-9]+).html$ $1.php教程?__is_apache_rewrite=1&__rewrite_arg=$2
</ifmodule>
四 要實現asp教程文章url到php文章的映射,在 第三步的<ifmodule mod_rewrite.c>和</ifmodule>之間添加:
rewritemap tolowercase int:tolower
rewritecond %{query_string} (?:boardid|page|id|replyid|star|skin)=d+ [nc]
rewriterule ^(.*(?:index|dispbbs)).asp$ $1.php?${tolowercase:%{query_string}}&__is_apache_rewrite=1
五 儲存httpd.conf並重啟apache。
下面看一下.htaccess檔案寫法,這是dz論壇的做法
# 將 rewriteengine 模式開啟
rewriteengine on
# 修改以下語句中的 /bbs 為你的論壇目錄位址,如果程式放在根目錄中,請將 /bbs 修改為 /
rewritebase /bbs
# rewrite 系統規則請勿修改
rewriterule ^archiver/((fid|tid)-[w-]+.html)$ archiver/index.php?$1
rewriterule ^forum-([0-9]+)-([0-9]+).html$ forumdisplay.php?fid=$1&page=$2
rewriterule ^thread-([0-9]+)-([0-9]+)-([0-9]+).html$ viewthread.php?tid=$1&extra=page%3d$3&page=$2
rewriterule ^space-(username|uid)-(.+).html$ space.php?$1=$2
rewriterule ^tag-(.+).html$ tag.php?name=$1
1、修改apache 的設定檔 httpd.conf 。將#loadmodule rewrite_module modules/mod_rewrite前面的#去掉
2、在 httpd.conf中添加:
<ifmodule mod_rewrite.c>
rewriteengine on
#...
</ifmodule>