2015-08-24 143 views
0

我试图做一个重写重定向页面ONLY:URL重写规则(IIS):重定向ONLY www.example.com和www.example.com/default.aspx

www.example.com/

www.example.com/default.aspx

我想让所有其他请求通过。我知道我非常接近,但我似乎无法让它完美。预先感谢任何&都帮助!

这是我到目前为止有:

<rewrite> 
    <rules> 

    <rule name="Base Redirect" stopProcessing="true"> 
     <match url="" /> 
     <conditions> 
      <add input="{HTTP_HOST}" pattern="www.example.com" ignoreCase="true" negate="false" /> 
     </conditions> 
     <action type="Redirect" redirectType="Permanent" url="shop.example.com" appendQueryString="true" /> 
    </rule> 

    <rule name="Default.aspx Redirect" stopProcessing="true"> 
     <match url="default.aspx" /> 
     <conditions> 
      <add input="{HTTP_HOST}" pattern="www.example.com" ignoreCase="true" negate="false" /> 
     </conditions> 
     <action type="Redirect" redirectType="Permanent" url="shop.example.com" appendQueryString="true" /> 
    </rule> 

    </rules> 
</rewrite> 

问题是它发送任何含有Default.aspx的(/pages/default.aspx等),我们不希望重定向任何东西,但根级别Default.aspx的。

菲利克斯

+0

你很接近你能证明你有什么 – Popnoodles

+0

添加了原帖子的代码。谢谢! – Felix

回答

0

试试这个(主要添加“^”字符来告诉正则表达式匹配只有当它是在开始:

<rule name="Base Redirect" patternSyntax="ECMAScript" stopProcessing="true"> 
    <match url="^$" /> 
    <conditions> 
       <add input="{HTTP_HOST}" pattern="www.example.com" /> 
    </conditions> 
    <action type="Redirect" url="http://shop.example.com/" appendQueryString="true" redirectType="Permanent" /> 
</rule> 

<rule name="Default.aspx Redirect" stopProcessing="true"> 
    <match url="^default.aspx" /> 
    <conditions> 
       <add input="{HTTP_HOST}" pattern="www.example.com" /> 
    </conditions> 
    <action type="Redirect" url="http://shop.example.com" appendQueryString="true" redirectType="Permanent" /> 
</rule> 
+0

太棒了!非常棒,非常感谢! – Felix