拥有一个ASP.NET解决方案,并希望实现两件事: -
所以......这就是我添加了webconfig的system.webserver部分......
<rewrite>
<rules>
<rule name="Remove WWW prefix" >
<match url="(.*)" ignoreCase="true" />
<conditions trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^www\.mydomain\.com" />
</conditions>
<action type="Redirect" url="{MapProtocol:{HTTPS}}://mydomain.com/{R:1}" redirectType="Permanent" />
</rule>
<rule name="homepage" stopProcessing="true" >
<match url="^/wwwzone/homepage.aspx$"/>
<action type="Redirect" url="/"/>
</rule>
<rule name="homepageReal" stopProcessing="true" >
<match url="^/$"/>
<action type="Rewrite" url="/somepath/homepage.aspx"/>
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapProtocol">
<add key="on" value="https"/>
<add key="off" value="http"/>
</rewriteMap>
</rewriteMaps>
</rewrite>
这失败了。这背后的逻辑是: -
任何想法都非常感激。
答案 0 :(得分:0)
我的正则表达式中的语法很差。
因此,匹配主页的真实URL应该是
<match url="^$"/>
不是
<match url="^/$"/>
随后重写为真实URL的规则应该以同样的方式改变。
所以,为了完整起见,这个有用......
<rewrite>
<rules>
<rule name="Remove WWW prefix" >
<match url="(.*)" ignoreCase="true" />
<conditions trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^www\.mydomain\.com" />
</conditions>
<action type="Redirect" url="{MapProtocol:{HTTPS}}://mydomain.com/{R:1}" redirectType="Permanent" />
</rule>
<rule name="homepage" stopProcessing="true" >
<match url="^wwwzone/homepage.aspx"/>
<action type="Redirect" url="/"/>
</rule>
<rule name="homepageReal" stopProcessing="true" >
<match url="^$"/>
<action type="Rewrite" url="/somepath/homepage.aspx"/>
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapProtocol">
<add key="on" value="https"/>
<add key="off" value="http"/>
</rewriteMap>
</rewriteMaps>
</rewrite>