gpt4 book ai didi

iis - 将所有裸域 url 重定向到保留 url 的子域 (www) url,IIS/ASP.NET 上的一页除外

转载 作者:行者123 更新时间:2023-12-03 16:29:41 25 4
gpt4 key购买 nike

实现上述目标的最佳方法是什么?我知道它可以在 HttpModule 级别实现。是否可以仅通过 web.config (代码执行更容易和更快)。

最佳答案

通过 web.config 使用 URL 重写模块很容易做到这一点:

<rewrite>
<rules>
<clear />
<rule name="Redirect naked domains to www.domain.com" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" negate="true" pattern="^www\." />
<add input="{REQUEST_URI}" negate="true" pattern="^noredirect/forthis/page\.aspx$" />
<add input="{REQUEST_URI}" negate="true" pattern="^noredirect/forthis/page-as-well\.aspx$" />
<add input="{REQUEST_URI}" negate="true" pattern="^noredirect/forthis/page-as-well-too\.aspx$" />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" redirectType="Permanent" />
</rule>
</rules>
</rewrite>

或者,如果您真的只有一个不需要重定向的页面,它甚至可以缩短为:
<rewrite>
<rules>
<clear />
<rule name="Redirect naked domains to www.domain.com" stopProcessing="true">
<match url="^noredirect/forthis/page\.aspx$" negate="true" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" negate="true" pattern="^www\." />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" redirectType="Permanent" />
</rule>
</rules>
</rewrite>

关于iis - 将所有裸域 url 重定向到保留 url 的子域 (www) url,IIS/ASP.NET 上的一页除外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13195315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com