IIS isapi_rewrite 重写

轩辕欣可
2023-12-01
 

ISAPI_Rewrite有Full和Lite两个版本。Full是商业版,Lite是免费版。
经过反复测试,发现Lite版只读取安装目录下的httpd.ini文件,而不会读取每个网站根目录下的httpd.ini。
只有Full版才会读取网站根目录下的httpd.ini配置。
刚才到官网上仔细查了Lite版的介绍,才发现原来官网上早已说明,只是我以前没有发现而已。
为了方便其他朋友区分Lite版和Full版,我把Lite版的简介翻译写在下面:

原文翻译
Lite version of ISAPI_Rewrite shares the same rewrite engine and features but with the following limitations:ISAPI_Rewrite的Lite版本使用(与Full版本)
相同的rewrite引擎和属性,但是有以下几点限制:
  • No support for distributed .htaccess configurations, directory and web site level configurations. Only one global httpd.conf configuration file will be loaded from Lite version installation folder.
  • 不支持分布式的.htaccess配置、目录和站点级
    配置。只有Lite版安装目录下的公用的httpd.conf
    (httpd.ini)配置文件会被读取。
  • No support for <VirtualHost>, <Directory>, <DirectoryMatch>, <Files>, <FilesMatch>, <Location> and <LocationMatch> tags.
  • 不支持<VirtualHost>、<Directory>、<DirectoryMatch>
    、<Files>、<FilesMatch>、<Location> 和<LocationMatch>标签.
  • There is no proxy module in Lite version, thus all proxy related functions like RewriteProxy directive and [P] flag will be ignored.
  • Lite版本中不包含代理模块,所以所有与代理有
    关的函数例如RewriteProxy指令和[P]标签都将无效。
  • No manual installation package for Lite version to install in a shared hosting environment.
  • 没有为Lite版安装在共享主机环境中的文档安装包
    (这条看不太懂,翻译的可能不对)
ISAPI_Rewrite Lite is completely free and it is a good solution for development or testing purposes and for small servers that host only a few web sites and don’t require distributed configurations or proxy functions.ISAPI_Rewrite Lite是完全免费的。如果只是以开发
或测试为目的,或者是一台仅有少量网站不需要分布配置
和代理功能的服务器,它将是一个很好的解决方案。

Rewrite规则相冲突解决办法 IIS isapi_rewrite full多站点配置方法

一、首先安装ISAPI_Rewrite (可以到网上找一个破解版或者购买一个正版,本文以isapi_rwf_0053.msi为例)

1、双击安装isapi_rwf_0053.msi 一路点击NEXT 直至完成;

2、安装完成后打开ISAPI_Rewrite目录中ISRWConfig.exe,输入注册码完成注册(如果是破解版的则无需这一步)。

3、安装完成后,如不能正常运行,请照以下说明设置ISAPI_Rewrite目录权限

    Administrators 和 SYSTEM 全部权限

    IIS_WPG   读取和运行/读取

    单独对ISAPI_Rewrite/ISAPI_Rewrite.dll设权限,加入Everyone的访问”读取”权限。

    打开IIS管理器,点击左边网站,右键-属性-ISAPI筛选器-然后定位到ISAPI_Rewrite\ISAPI_Rewrite.dll确定启用,然后重启IIS生效。

   通过上面的安装与设置后,rewrite已经可以使用了。

二、多站点的配置方法

如果你在一台服务器上安装了多个网站,而且都希望实现伪静态,那可以采用全局的方式配置,全局配置方式跟ISAPI_Rewrite免费版是一样的,即把规则全部写到安装目录下的httpd.ini(有些版本为httpd.conf)中,重启iis即可;这里主要说一下全局配置结合独立配置的方法:

1、对于不会影响到其它网站正常运行的规则,可以考虑写到全局设置里。

# 以下是DZ6.0/6.1/7.0论坛+UCHome Rewrite规则

# 此默认规则只针对UCHome程序放在根目录中用独立域名访问的,论坛也可以直接用.
RewriteRule ^(.*)/archiver/((fid|tid)-[\w\-]+\.html)\?*(.*)$ $1/archiver/index\.php\?$2&$4
RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+)\.html\?*(.*)$ $1/forumdisplay\.php\?fid=$2&page=$3&$4
RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html\?*(.*)$ $1/viewthread\.php\?tid=$2&extra=page\%3D$4&page=$3&$4
RewriteRule ^(.*)/space-(username|uid)-(.+)\.html\?*(.*)$ $1/space\.php\?$2=$3&$4
RewriteRule ^(.*)/tag-(.+)\.html\?*(.*)$ $1/tag\.php\?name=$2&$3
#uch放在根目录时的伪静态
RewriteRule ^/(space|network)-(.+)\.html$ /$1\.php\?rewrite=$2 [L]
RewriteRule ^/(space|network)\.html$ /$1\.php [L]
RewriteRule ^/([0-9]+)$ /space\.php\?uid=$1 [L]
#uch放在二级目录时的伪静态
RewriteRule ^/uhome/(space|network)-(.+)\.html$ /uhome/$1\.php\?rewrite=$2 [L]
RewriteRule ^/uhome/(space|network)\.html$ /uhome/$1\.php [L]
RewriteRule ^/uhome/([0-9]+)$ /uhome/space\.php\?uid=$1 [L]

# 以下是Ecshop重写规则
#RewriteRule ^(.*)/index.html    $1/index.php [I]
#RewriteRule ^(.*)/default.html $1/index.php [I]
# access any object by its numeric identifier
RewriteRule /feed-c([0-9]+)\.xml /feed\.php\?cat=$1
RewriteRule /feed-b([0-9]+)\.xml /feed\.php\?brand=$1
RewriteRule /feed\.xml$                 feed\.php
RewriteRule /category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html /category\.php\?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5&page=$6&sort=$7&order=$8
RewriteRule /category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)(.*)\.html /category\.php\?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5
RewriteRule /category-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html /category\.php\?id=$1&brand=$2&page=$3&sort=$4&order=$5
RewriteRule /category-([0-9]+)-b([0-9]+)-([0-9]+)(.*)\.html /category\.php\?id=$1&brand=$2&page=$3
RewriteRule /category-([0-9]+)-b([0-9]+)(.*)\.html /category\.php\?id=$1&brand=$2
RewriteRule /category-([0-9]+)(.*)\.html /category\.php\?id=$1
RewriteRule /goods-([0-9]+)(.*)\.html /goods\.php\?id=$1
RewriteRule /article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html /article_cat\.php\?id=$1&page=$2&sort=$3&order=$4
RewriteRule /article_cat-([0-9]+)-([0-9]+)(.*)\.html /article_cat\.php\?id=$1&page=$2
RewriteRule /article_cat-([0-9]+)(.*)\.html /article_cat\.php\?id=$1
RewriteRule /article-([0-9]+)(.*)\.html /article\.php\?id=$1
RewriteRule /brand-([0-9]+)-c([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)\.html /brand\.php\?id=$1&cat=$2&page=$3&sort=$4&order=$5
RewriteRule /brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*)\.html /brand\.php\?id=$1&cat=$2&page=$3
RewriteRule /brand-([0-9]+)-c([0-9]+)(.*)\.html /brand\.php\?id=$1&cat=$2
RewriteRule /brand-([0-9]+)(.*)\.html /brand\.php\?id=$1
RewriteRule /tag-(.*)\.html /search\.php\?keywords=$1
RewriteRule /snatch-([0-9]+)\.html /snatch\.php\?id=$1
RewriteRule /group_buy-([0-9]+)\.html /group_buy\.php\?act=view&id=$1
RewriteRule /auction-([0-9]+)\.html /auction\.php\?act=view&id=$1
#以下是modoer伪静态规则for1.1
#首页去除首页规则,不然会引起其它子站出错
#RewriteRule ^(.*)/index\.html\?*(.*)$ $1/index\.php [L]
#TAG标签页
RewriteRule ^(.*)/shop/tag\.html\?*(.*)$ $1/shop/tag\.php [L]
RewriteRule ^(.*)/shop/tag_(.+)\.html\?*(.*)$ $1/shop/tag\.php\?tagname=$2 [L]
#商铺大全
RewriteRule ^(.*)/shop/cate_([0-9]+)\.html\?*(.*)$ $1/shop/cate\.php\?cd=$2 [L]
RewriteRule ^(.*)/cate_([0-9]+)_([a-z]+)_([0-9]+)\.html\?*(.*)$ $1/shop/cate\.php\?cd=$2&order=$3&page=$4 [L]
#RewriteRule ^shop/cate_([0-9]+)(\.html|) shop/cate.php?cd=$1
#RewriteRule ^shop/cate_([0-9]+)_([a-z]+)_([0-9]+)(\.html|) shop/cate.php?cd=$1&order=$2&page=$3
#商铺页面
RewriteRule ^(.*)/shop/([0-9]+)\?*(.*)$ $1/shop/shop\.php\?shopid=$2$3 [L]
#RewriteRule ^shop/(shop_|)([0-9]+)(\.html|)$ shop/shop.php?shopid=$2$3
#点评内容页面
RewriteRule ^(.*)/shop/viewreview_([0-9]+)\.html\?*(.*)$ $1/shop/viewreview\.php\?reviewid=$2 [L]
RewriteRule ^(.*)/shop/viewreview_([0-9]+)\.html#respond$\?*(.*)$ $1/shop/viewreview.php?reviewid=$2#respond [L]
#个人空间
RewriteRule ^(.*)/space/([0-9]+)$ $1/space/index\.php\?suid=$2 [L]
RewriteRule ^(.*)/space/([0-9]+)_([a-z]+)\?*(.*)$ $1/space/index\.php\?suid=$2&n=$3 [L]
#兑奖中心
RewriteRule ^(.*)/exchange/gift_([0-9]+)\.html\?*(.*)$ $1/exchange/index\.php\?action=gift&giftid=$2 [L]
#优惠券,这个有问题,不用
#RewriteRule ^(.*)/coupon/([0-9]+)\?*(.*)$ $1/coupon/index\.php\?ac=detail&couponid=$2$3 [L]
#新闻资讯
RewriteRule ^(.*)/article/([0-9]+)\.html\?*(.*)$ $1/article/article\.php\?articleid=$2 [L]
RewriteRule ^(.*)/article/classid_([0-9]+)\.html\?*(.*)$ $1/article/index\.php\?classid=$2 [L]

—————————————————————————
如果有采用以上几个系统的,可以把以上规则写到全局设置里。

2、某些站点比较特殊,把它的规则写到全局配置会影响到其它站点的正常运行,那么就要对该站点进行独立配置。例如ecmall的就会导致其它站点出问题。

# 以下Ecmall重写规则
# 为了确保重写规则不影响服务器上的其他站点
# 请将下面的语句前的#号去掉,并将(?:www\.)?site1\.com改为商店所在域名
RewriteCond %{HTTP:Host} (?:mall\.)?ynczw\.net
RewriteRule ^(.*)/index.html$   $1/index.php [I]
RewriteRule ^(.*)/([a-zA-Z0-9]+)_(.*)\.html$ $1/index\.php\?app=$2&arg=$3 [I]

三、特别说明

1、刚开装好ISAPI_Rewrite,全局重写正常而独立站点重写失败的解决办法:在需要使用rewrite的站点根目录下创建httpd.ini文件,并且给相应用户的读权限,添加Everyone访问

并且一定要以以下语句开头
[ISAPI_Rewrite]

RewriteCond Host: www\.1100do\.cn (此处网址改成你的网址)

 

原文地址:http://www.85904.com/post/170.html

 类似资料: