Mod rewrite 将mod_重写规则转换为IIS重写规则

Mod rewrite 将mod_重写规则转换为IIS重写规则,mod-rewrite,iis-7,url-rewriting,Mod Rewrite,Iis 7,Url Rewriting,我正在使用生成我的网站,其中包括.htaccess mod_rewrite rules,但我将使用IIS在Windows服务器上自托管我的网站,因此我尝试将现有的.htaccess规则导入IIS rewrite模块,但它导入的规则无法正常工作 我想重写的URL示例如下: http://example.org.uk/about/ Rewrites to http://example.org.uk/about/about.html ----------- http://example.org

我正在使用生成我的网站,其中包括.htaccess mod_rewrite rules,但我将使用IIS在Windows服务器上自托管我的网站,因此我尝试将现有的.htaccess规则导入IIS rewrite模块,但它导入的规则无法正常工作

我想重写的URL示例如下:

http://example.org.uk/about/

Rewrites to

http://example.org.uk/about/about.html

-----------

http://example.org.uk/blog/events/

Rewrites to

http://example.org.uk/blog/events.html

-----------

http://example.org.uk/blog/2010/11/foo-bar

Rewrites to

http://example.org.uk/blog/2010/11/foo-bar.html
目录和文件名是通用的,可以是任何值。我在Apache中使用的.htaccess的副本如下所示

# initialize mod_rewrite
RewriteEngine on
RewriteBase /

# remove the www from the url
# RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
# RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

###  BEGIN GENERATED REWRITE RULES  ####

RewriteCond %{REQUEST_FILENAME}/index.html -f
RewriteRule ^(.*) $1/index.html

####  END GENERATED REWRITE RULES  ####

# listing pages whose names are the same as their enclosing folder's
RewriteCond %{REQUEST_FILENAME}/$1.html -f
RewriteRule ^([^/]*)/$ %{REQUEST_FILENAME}/$1.html

# regular pages
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^.*$ %{REQUEST_FILENAME}.html

# set our custom 404 page
ErrorDocument 404 /404.html
我尝试过各种ISAPI重写模块,但都没有成功,因此我更愿意将规则转换为本机IIS重写规则。我们非常感谢您对这一问题的帮助

编辑:

我已经解决了2/3的规则,只是以下几条我似乎无法开始工作

            <rule name="Imported Rule 1" stopProcessing="false">
                <match url="^([^/]+)/$" ignoreCase="false" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{R:0}/{R:1}.html" matchType="IsFile" />
                </conditions>
                <action type="Rewrite" url="{R:0}/{R:1}.html" />
            </rule>


它将
about/
映射到
about/about.html
,它只是继续显示目录列表。

我总是尽量避免这种情况。所以我只使用URL重写器,它允许我在使用IIS时粘贴Apache规则。这将是ISAPI_Rewrite 3(LITE版本是免费的),或者,这也是3个或更少网站的免费版本。从那时起,我从来没有像你这样头痛过