2013-04-25 133 views
2

我在本网站的帮助下构建了重写规则。 但我仍然有一个小问题。IIS重写规则 - 隐藏目录(规则无法正常工作)

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

例如:

www.mywebsite.com/uk/editions/ 

应重新写入

www.mywebsite.com/editions/ 

(删除目录UK)

上述场景现在正在为所有网址,除了一。

英国主页位于这里。 (index.html

www.mywebsite.com/uk/ 

而作为

www.mywebsite.com 

,而不是它显示了www根index.html而不是uk/index.html页面正确的重新写入规则应显示的URL。

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

www.mywebsite.com/uk/index.html 

它正确重写URL到

www.mywebsite.com 

,并显示英国索引页,而不是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> 

回答

0

这个问题来自于第二个规则的有(Rewrite the URL after UK is hidden)。

在你的条件,你必须:

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

那些2线的意思是,如果请求的URL物理路径相匹配的文件或目录,它不会执行重写。

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

+0

非常感谢你,我会修改我的规则,并让你知道我如何得到。 – user1611258 2013-05-01 08:18:20