1 ͨϵͳСǷΪ̬ URL ̬ Ĵ򿪻ر

2 ܶԷҪ󣬶ûҪ Web Ӧ Rewrite ҪȨ޲ſʹáûҪĿռ̽ѯռǷ֧ Rewrite ԼǷֶ֧վĿ¼ .htaccess ļֻURL ̬ ܲŻЧ

3  URL ̬ ̳һЩӻ http://www.demo.com/cat-1.html ʽķֻ֧δúãЩӻ֡ҳ޷ʾĴϢ̳޷ʡ޷ʵʱ̨ر URL ̬ ܣ̳ɻָ״̬ 

urlrewriteܵԼڿ˹֮ǰ Web ѡӦĻ÷пɷ޷߹Ч½ṩ Apache  Zeus ÷IIS  Web ɸԭ޸ġ


----- Apache Web Serverû

ȷʹõ Apache 汾Ƿ mod_rewrite ģ顣 

Apache 1.x û conf/httpd.conf Ƿδ룺 

LoadModule rewrite_module     libexec/mod_rewrite.so
AddModule mod_rewrite.c

Apache 2.x û conf/httpd.conf Ƿһδ룺 

LoadModule rewrite_module     modules/mod_rewrite.so

ڣôļͨ conf/httpd.confм´롣ʱע⣬վʹͨ壬ؼӵã <VirtualHost> ȥⲿ޷ʹáĺúȻ Apache  

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/index\.html$ $1/index.php
RewriteRule ^(.*)/cat-([0-9]+)\.html$ $1/category.php?id=$2
RewriteRule ^(.*)/cat-([0-9]+)-page-([0-9]+)\.html$ $1/category.php?id=$2&page=$3
RewriteRule ^(.*)/cat-([0-9]+)-area-([0-9]+)\.html$ $1/category.php?id=$2&area=$3
RewriteRule ^(.*)/cat-([0-9]+)-area-([0-9]+)-page-([0-9]+)\.html$ $1/category.php?id=$2&area=$3&page=$4
RewriteRule ^(.*)/view-([0-9]+)\.html$ $1/view.php?id=$2
RewriteRule ^(.*)/about-([0-9]+)\.html$ $1/about.php?id=$2
RewriteRule ^(.*)/bianmin\.html$ $1/bianmin.php

RewriteRule ^(.*)/help\.html$ $1/help.php?act=list
RewriteRule ^(.*)/help-list-([0-9]+)\.html$ $1/help.php?act=list&typeid=$2
RewriteRule ^(.*)/help-list-([0-9]+)-page-([0-9]+)\.html$ $1/help.php?act=list&typeid=$2&page=$3
RewriteRule ^(.*)/help-page-([0-9]+)\.html$ $1/help.php?act=list&page=$2
RewriteRule ^(.*)/help-view-([0-9]+)\.html$ $1/help.php?act=view&id=$2

RewriteRule ^(.*)/article\.html$ $1/article.php?act=list
RewriteRule ^(.*)/article-list-([0-9]+)-page-([0-9]+)\.html$ $1/article.php?act=list&typeid=$2&page=$3
RewriteRule ^(.*)/article-list-([0-9]+)\.html$ $1/article.php?act=list&typeid=$2
RewriteRule ^(.*)/article-page-([0-9]+)\.html$ $1/article.php?act=list&page=$2
RewriteRule ^(.*)/article-view-([0-9]+)\.html$ $1/article.php?act=view&id=$2

RewriteRule ^(.*)/com\.html$ $1/com.php
RewriteRule ^(.*)/com-list-([0-9]+)\.html$ $1/com.php?act=list&catid=$2
RewriteRule ^(.*)/com-list-([0-9]+)-page-([0-9]+)\.html$ $1/com.php?act=list&page=$2
RewriteRule ^(.*)/com-list-([0-9]+)-area-([0-9]+)\.html$ $1/com.php?act=list&catid=$2&area=$3
RewriteRule ^(.*)/com-list-([0-9]+)-area-([0-9]+)-page-([0-9]+)\.html$ $1/com.php?act=list&catid=$2&area=$3&page=$4

RewriteRule ^(.*)/com-area-([0-9]+)\.html$ $1/com.php?act=list&area=$2
RewriteRule ^(.*)/com-view-([0-9]+)\.html$ $1/com.php?act=view&id=$2
</IfModule>


--------Apache Web Serverû

ڿʼ֮ǰѯĿռ̣ռǷ֧ Rewrite ԼǷֶ֧վĿ¼ .htaccess ļ򼴱㰴ķúˣҲ޷ʹá 

վĿ¼Ƿ .htaccess ļڣֹļWin32 ϵͳ£޷ֱӽ .htaccess ļԴ䱾Ŀ¼пһݡ

--------IIS Web Serverû

 IIS  Isapi ɸѡûпʵiisα̬ģļµģ飬ɸѡΪ Rewrite ִļѡ Rewrite.dll  IIS httpd.ini Ѿúã£ 

[ISAPI_Rewrite]

# 3600 = 1 hour
CacheClockRate 3600

RepeatLimit 32

# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP

RewriteRule ^(.*)/index\.html\?*(.*)$                  $1/index\.php
RewriteRule ^(.*)/cat-([0-9]+)\.html\?*(.*)$           $1/category.php\?id=$2
RewriteRule ^(.*)/cat-([0-9]+)-page-([0-9]+)\.html\?*(.*)$ $1/category.php\?id=$2&page=$3
RewriteRule ^(.*)/cat-([0-9]+)-area-([0-9]+)\.html\?*(.*)$ $1/category.php\?id=$2&area=$3
RewriteRule ^(.*)/cat-([0-9]+)-area-([0-9]+)-page-([0-9]+)\.html\?*(.*)$ $1/category.php\?id=$2&area=$3&page=$4
RewriteRule ^(.*)/view-([0-9]+)\.html\?*(.*)$          $1/view.php\?id=$2
RewriteRule ^(.*)/about-([0-9]+)\.html\?*(.*)$         $1/about.php\?id=$2
RewriteRule ^(.*)/bianmin\.html$ $1/bianmin.php
RewriteRule ^(.*)/help\.html\?*(.*)$          $1/help.php\?act=list
RewriteRule ^(.*)/help-list-([0-9]+)\.html$    $1/help.php\?act=list&typeid=$2
RewriteRule ^(.*)/help-list-([0-9]+)-page-([0-9]+)\.html$ $1/help.php\?act=list&typeid=$2&page=$3
RewriteRule ^(.*)/help-page-([0-9]+)\.html$ $1/help.php\?act=list&page=$2
RewriteRule ^(.*)/help-view-([0-9]+)\.html$ $1/help.php\?act=view&id=$2

RewriteRule ^(.*)/article\.html$ $1/article.php\?act=list
RewriteRule ^(.*)/article-list-([0-9]+)-page-([0-9]+)\.html$ $1/article.php\?act=list&typeid=$2&page=$3
RewriteRule ^(.*)/article-list-([0-9]+)\.html$ $1/article.php\?act=list&typeid=$2
RewriteRule ^(.*)/article-page-([0-9]+)\.html$ $1/article.php\?act=list&page=$2
RewriteRule ^(.*)/article-view-([0-9]+)\.html$ $1/article.php\?act=view&id=$2

RewriteRule ^(.*)/com\.html$ $1/com.php
RewriteRule ^(.*)/com-list-([0-9]+)\.html$ $1/com.php\?act=list&catid=$2
RewriteRule ^(.*)/com-list-([0-9]+)-page-([0-9]+)\.html$ $1/com.php\?act=list&page=$2
RewriteRule ^(.*)/com-list-([0-9]+)-area-([0-9]+)\.html$ $1/com.php\?act=list&catid=$2&area=$3
RewriteRule ^(.*)/com-list-([0-9]+)-area-([0-9]+)-page-([0-9]+)\.html$ $1/com.php\?act=list&catid=$2&area=$3&page=$4
RewriteRule ^(.*)/com-area-([0-9]+)\.html$ $1/com.php\?act=list&area=$2
RewriteRule ^(.*)/com-view-([0-9]+)\.html$ $1/com.php\?act=view&id=$2