将mod_rewrite规则转换为IIS重写规则
问题描述:
我使用http://github.com/lakshmivyas/hyde来生成我的网站,它包括.htaccess mod_rewrite规则,但是我将在使用IIS的Windows服务器上自我托管我的网站,所以我是试图将现有的.htaccess规则导入到IIS Rewrite模块中,但它导入的规则无法正常工作。我想重写URL的将mod_rewrite规则转换为IIS重写规则
的例子是:
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版本是免费的),或者Ape,这对于3个或更少的网站也是免费的。从那时起,从来没有像你的头痛。