【问题标题】:Converting mod_rewrite Rules to IIS Rewrite Rules将 mod_rewrite 规则转换为 IIS 重写规则
【发布时间】:2010-11-26 21:33:28
【问题描述】:

我正在使用http://github.com/lakshmivyas/hyde 生成我的网站,它包含 .htaccess mod_rewrite 规则,但我将使用 IIS 在 Windows 服务器上自托管我的网站,所以我试图导入现有的.htaccess 规则到 IIS 重写模块,但它导入的规则不能正常工作。

我想重写的 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,它只是继续显示目录列表。

【问题讨论】:

    标签: mod-rewrite iis-7 url-rewriting


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2012-07-12
      • 2014-07-03
      • 2016-01-02
      • 2013-08-09
      • 2014-10-29
      • 2011-04-25
      • 1970-01-01
      • 1970-01-01
      • 2013-12-01
      相关资源
      最近更新 更多