本文介绍了将所有裸域URL重定向到保留URL的子域(www)URL,IIS / ASP.NET上的一个页面除外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是实现上述目标的最佳方法?我知道它可以在HttpModule级别实现。是否可以通过web.config(更容易和更快地执行代码)。
Whats the best way to achieve the above? I do know that it can be achieved at HttpModule level. Is it possible just via web.config(easier and faster to code execute).
推荐答案
使用URL轻松完成此操作通过web.config重写模块:
It's easy to do this with the URL rewrite module through the web.config :
<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>
或者如果你真的只有一个页面不需要重定向,它可以是甚至缩短为:
Or if you really only have a single page that doesn't need to be redirected, it can be even shortened to:
<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>
这篇关于将所有裸域URL重定向到保留URL的子域(www)URL,IIS / ASP.NET上的一个页面除外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!