建站代码网

热门标签

asp网站伪静态化URL Rewrite中的httpd.ini伪静态化规则编写方法

实现asp伪静态化首先要服务器空间要支持rewrite重写,然后是URL Rewrite中的httpd.ini伪静态化规则编写,伪静态Rewrite规则编写方法是新建一个httpd.ini,里面写上类似如下代码,再将写好的httpd.ini上传到你网站的根目录下,这个是我做的一个网站所用到的伪静态规则,当然每个人的网站,规则写得当然不一样,但形式是差不多的,

正如我下面有

shownews.asp?id=xx可写伪静态规则

RewriteRule /shownews-([0-9,a-z]*).html /shownews.asp?id=$1,

如后面带参数如BigClassName=一个大类&SmallClassName=一个小类,这样的规则可写成RewriteRule /product-(.*?)-(.*?).html /product.asp?BigClassName=$1&SmallClassName=$2,这规则里面用到的都是写正则表达式,想了解正在表达式可以在网上看下相关的资料。


[ISAPI_Rewrite]  

# 3600 = 1 hour  

CacheClockRate 3600  

RepeatLimit 32  

# Block external access to the httpd.ini and httpd.parse.errors files


RewriteRule /shownews-([0-9,a-z]*).html /shownews.asp?id=$1


RewriteRule /showproduct-([0-9,a-z]*).html /showproduct.asp?id=$1


RewriteRule /noteshow-([0-9,a-z]*).html /noteshow.asp?id=$1


RewriteRule /news-(.*?).html /news.asp?BigClassName=$1


RewriteRule /about-(.*?).html /about.asp?BigClassName=$1


RewriteRule /product-(.*?).html /product.asp?BigClassName=$1


RewriteRule /product-(.*?)-(.*?).html /product.asp?BigClassName=$1&SmallClassName=$2


RewriteRule /news-(.*?)-(.*?).html /news.asp?BigClassName=$1 [N,I,L,O]&SmallClassName=$2 [N,I,L,O]


RewriteRule /product-(.*?)-([0-9,a-z]*).html /product.asp?BigClassName=$1 [N,I,L,O]&page=$2


RewriteRule /news-(.*?)-([0-9,a-z]*).html /news.asp?BigClassName=$1 [N,I,L,O]&page=$2


RewriteRule /news-(.*?)-(.*?)-([0-9,a-z]*).html /news.asp?BigClassName=$1&SmallClassName=$2 [N,I,L,O]&page=$3


RewriteRule /product-(.*?)-(.*?)-([0-9,a-z]*).html /product.asp?BigClassName=$1&SmallClassName=$2 [N,I,L,O]&page=$3


RewriteRule /notebook-(.*?)-(.*?)-([0-9,a-z]*).html /notebook.asp?BigClassName=$1&SmallClassName=$2 [N,I,L,O]&page=$3


RewriteRule /notebook-([0-9,a-z]*).html /notebook.asp?page=$1


RewriteRule /httpd(?:.ini|.parse.errors).* / [F,I,O]  

# Block external access to the Helper ISAPI Extension  

RewriteRule .*.isrwhlp / [F,I,O]  

RewriteRule /index.html /index.asp $1  

RewriteRule /news.html /news.asp $1  

RewriteRule /notebook.html /notebook.html $1



RewriteRule .*.isrwhlp / [F,I,O] RewriteRule /index.html /index.asp $1RewriteRule /news.html /news.asp $1RewriteRule /notebook.html /notebook.html $1  


下面还有种写法,我没用过,是网上别人那复制过来的


httpd.ini 内容写法如下:


[ISAPI_Rewrite]  

# 3600 = 1 hour  

CacheClockRate 3600  

RepeatLimit 32  

# Block external access to the httpd.ini and httpd.parse.errors files  

RewriteRule /httpd(?:.ini|.parse.errors).* / [F,I,O]  

# Block external access to the Helper ISAPI Extension  

RewriteRule .*.isrwhlp / [F,I,O]  

RewriteRule ^(.*)/index.asp $1/index.html  

RewriteRule ^(.*)/([0-9]*).html $1/article.asp?id=$2  

RewriteRule ^(.*)/([a-z]*)/([a-z]*)/ $1/list.asp?x=$2&y=$3


该规则具体说明:  

RewriteRule ^(.*)/index.asp $1/index.html  

是将index.asp 伪静态为index.html  

RewriteRule ^(.*)/([0-9]*).html $1/article.asp?id=$2  

文章页伪静态,把article.asp?id=xxx映射成 /xxx.html ,其中xxx为文章ID号,在article.asp中接收id, id=request(“id”), 根据ID有数据库中取数据即可  

RewriteRule ^(.*)/([a-z]*)/([a-z]*)/ $1/list.asp?x=$2&y=$3  

文章列表页伪静态, 把/list.asp?x=$2&y=$3 映射成 如:/news/sports/ 格式,$2对应news,$3对应 sports ,在数据库中取news中sports文章显示即可其中([a-z]*)代表任意字母,([0-9]*)代表数字




使用ISAPI_Rewrite来实现:

(2.X版本文件为httpd.ini,3.X版本文件为.htaccess,文件放在网站根目录生效)

1. 将不带$

RewriteRule (.*) http://$1 [I,RP]
X