[英]WebConfig URL Rewrites in IIS
有一個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>
這失敗了。 其背后的邏輯是:-
任何想法表示贊賞。
這反過來使我在正則表達式中的語法不佳。
因此,匹配首頁的真實網址應該是
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.