使用 URL Rewrite 在 IIS 8 中重现多个 apache 重写

reproduce multiple apache rewrites in IIS 8 with URL Rewrite

我以前的网络服务器 运行 apache,在每个站点的 .conf 文件中都进行了重写。我什至不认为自己是中级重写用户,所以这可能并不理想。我正在尝试重现此内容:

# except for requests for URL-path /abc/abc_system<whatever> 
RewriteCond %{REQUEST_URI} !^(/abc/abc_system|/abc/themes|/abc/admin.php)
RewriteCond %{HTTP_HOST} ^([^.]+\.)*abctest\.example\.com [NC]
RewriteRule ^/abc/(.*)$ /abc/index.php/abc/ [L]
# one
RewriteRule ^/one/(.*)$ /one/index.php/one/ [L]
# two
RewriteRule ^/two/(.*)$ /two/index.php/two/ [L]
# three
RewriteRule ^/three/(.*)$ /three/index.php/three/ [L]

在 IIS 8 中使用 URL 重写。

<rewrite>
    <rules>
        <clear />
        <rule name="abc ee" stopProcessing="false">
            <match url="^abc/(.*)$" ignoreCase="true" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{URL}" pattern="^(/abc/abc_system|/abc/themes|/abc/admin.php)" ignoreCase="false" negate="true" />
                <add input="{HTTP_HOST}" pattern="^([^.]+\.)*abctest\.example\.com" />
            </conditions>
            <action type="Rewrite" url="/abc/index.php/abc/{R:1}" logRewrittenUrl="true" />
        </rule>
        <rule name="abc one" stopProcessing="false">
            <match url="^/one/(.*)$" ignoreCase="true" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            </conditions>
            <action type="Rewrite" url="/one/index.php/one/{R:1}" logRewrittenUrl="true" />
        </rule>
    </rules>
</rewrite>

第一条规则有效,但第二条 ("abc one") 无效,所以我什至还没有为 "two" 和 "three" 添加规则。

基本上 url 看起来像这样:

示例。com/abc -> 示例。com/abc/index.php/abc(工作)

示例。com/one -> 示例。com/one/index.php/one

示例。com/two -> 示例。com/two/index.php/two

示例。com/three -> 示例。com/three/index.php/three

第二条规则不起作用,我做错了什么? 一旦解决了这个问题,重复它是解决问题的最佳方法还是有更有效的方法来压缩它们?

非常感谢!

您可以使用 "OR" 来捕获 two/three 情况并且会更快,我测试了以下规则并且工作正常:

            <rule name="RewriteOneTwoThree" stopProcessing="true">
                <match url="^(one|two|three)/(.*)$" ignoreCase="false" />
                <action type="Rewrite" url="/{R:1}/index.php/{R:1}/{R:2}" />
            </rule>