IIS重写规则-隐藏目录(规则无法正常工作)

IIS重写规则-隐藏目录(规则无法正常工作),iis,redirect,url-rewriting,rewrite,hide,Iis,Redirect,Url Rewriting,Rewrite,Hide,在这个网站的帮助下,我构建了一个重写规则。 但我仍然有一个小问题 我的目标是从URL中删除某个目录 例如: www.mywebsite.com/uk/editions/ 应重新写信给 www.mywebsite.com/editions/ (正在删除目录) 以上场景现在适用于除一个URL之外的所有URL 英国主页实际位于此处。(index.html) 正确的重写规则应将URL显示为 www.mywebsite.com 相反,它显示的是www rootindex.html,而不是uk/i

在这个网站的帮助下,我构建了一个重写规则。 但我仍然有一个小问题

我的目标是从URL中删除某个目录

例如:

www.mywebsite.com/uk/editions/ 
应重新写信给

www.mywebsite.com/editions/
(正在删除目录)

以上场景现在适用于除一个URL之外的所有URL

英国主页实际位于此处。(
index.html

正确的重写规则应将URL显示为

www.mywebsite.com 
相反,它显示的是www root
index.html
,而不是
uk/index.html
页面

但是如果我像这样在URL中指定索引页

www.mywebsite.com/uk/index.html
它正确地将URL重写为

www.mywebsite.com 
并显示UK索引页,而不是www根索引页

我使用的规则如下:

<rule name="Hide UK Directory in URL" enabled="true" stopProcessing="true">
    <match url="^uk$|^uk/(.*)$" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^www\.mywebsite\.com$" />
    </conditions>
    <action type="Redirect" url="{R:1}" logRewrittenUrl="true" />
</rule>

<rule name="Rewrite the URL after UK is hidden" enabled="true" stopProcessing="true">
    <match url="^(?!uk)(.*)" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^www\.mywebsite\.com$" />
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="uk/{R:1}" logRewrittenUrl="true" />
</rule>

这个问题来自您的第二条规则(
在UK被隐藏后重写URL

在您的条件下,您有:

<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />

这两行表示,如果请求的URL与文件或目录的物理路径匹配,则不会执行重写


当您请求
www.mywebsite.com
时,它会匹配到目录的物理路径,因此不会执行该规则。

非常感谢,我将修改我的规则并让您知道我的进展情况。
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />