[英]WebConfig URL Rewrites in IIS
Have a ASP.NET solution and want to achieve 2 things: - 有一个ASP.NET解决方案,并希望实现以下两点:-
So ... here is what I have added the system.webserver section of the webconfig... 所以...这就是我添加的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>
This fails. 这失败了。 The logic behind this is: - 其背后的逻辑是:-
Any thoughts much appreciated. 任何想法表示赞赏。
It turns our was poor syntax in my regular expressions. 这反过来使我在正则表达式中的语法不佳。
So, matching the real URL of the home page should have been 因此,匹配首页的真实网址应该是
<match url="^$"/>
not 不
<match url="^/$"/>
And the subsequent rule to rewrite to the real URL should change in the same way. 并且随后的重写为真实URL的规则应以相同的方式更改。
So, for completeness, this one works... 因此,为了完整起见,这一行有效...
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.