IIS7官方: http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/
微软在IIS7中添加了URL的重写模块,并且免费使用,可以导入.htaccess规则,确实是个不错的选择
URL Rewrite Module
URL Rewrite Module是一个基于规则的URL重写引擎,用于在URL被Web服务器处理之前改变请求的URL。对于动态Web应用程序,它可以为用户和搜索引擎提供友好的URL,URL重写和重定向是基于HTTP头和服务器变量的,并可以对站点内容进行访问控制。
iis 7的主机才支持伪静态模块.
<?xml version=”1.0″ encoding=”UTF-8″?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name=”topic”>
<match url=”^topic-(.+)\.html$” />
<action type=”Rewrite” url=”portal.php?mod=topic&topic={R:1}” />
</rule>
<rule name=”article”>
<match url=”article-([0-9]+)\.html$” />
<action type=”Rewrite” url=”portal.php?mod=view&aid={R:1}” />
</rule>
<rule name=”forum”>
<match url=”^forum-([0-9]+)-([0-9]+)\.html$” ignoreCase=”false” />
<action type=”Rewrite” url=”forum.php?mod=forumdisplay&fid={R:1}&page={R:2}” appendQueryString=”false” />
</rule>
<rule name=”thread”>
<match url=”^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$” />
<action type=”Rewrite” url=”forum.php?mod=viewthread&tid={R:1}&extra=page={R:2}&page={R:3}” />
</rule>
<rule name=”group”>
<match url=”^group-([0-9]+)-([0-9]+)\.html$” />
<action type=”Rewrite” url=”forum.php?mod=group&fid={R:1}&page={R:2}” />
</rule>
<rule name=”space”>
<match url=”^space-(username|uid)-(.+)\.html$” />
<action type=”Rewrite” url=”home.php?mod=space&{R:1}={R:2}” />
</rule>
<rule name=”Xrewrite”>
<match url=”^([a-z]+)-(.+)\.html$” />
<action type=”Rewrite” url=”{R:1}.php?rewrite={R:2}” />
</rule>
</rules>
</rewrite>
<httpErrors errorMode=”Detailed” />
<asp scriptErrorSentToBrowser=”true” />
</system.webServer>
<system.web>
<customErrors mode=”Off” />
<globalization requestEncoding=”utf-8″ responseEncoding=”utf-8″ fileEncoding=”utf-8″ />
</system.web>
</configuration>
------------------------------------------------------------------
index301.htaccess 必须写到.htaccess后缀的文件里,
1.在iis7的URL Rewrite中右侧点击Import Rules导入.htaccess文件
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^henghengw.com$ [NC]
RewriteRule ^(.*)$ http://www.henghengw.com/$1
[R=301,L]
</IfModule>
其实应该也可以试试直接在web.config里写规则
<rule name="index301" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^henghengw.com$" />
</conditions>
<action type="Redirect" url="http://www.henghengw.com/{R:1
}" redirectType="Permanent" />
</rule>