重定向“non-www"URL到"网址"URL
本文关键字:quot URL 网址 重定向 non-www | 更新日期: 2023-09-27 17:50:20
我有一个运行在HTTP和HTTPS上的MVC4应用程序。基本上,我想确保所有非www请求直接到www。版本,不管他们使用的是什么协议。我正在努力定义这在URL重写为我的网络。将以下代码添加到<server.webserver>
节点
<rewrite>
<rules>
<rule name="Redirect to www" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^domain.com$" />
</conditions>
<action type="Redirect"
url="{MapProtocol:{HTTPS}}://www.domain.com/{R:1}" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapProtocol">
<add key="on" value="https" />
<add key="off" value="http" />
</rewriteMap>
</rewriteMaps>
</rewrite>
关于如何在IIS中创建重定向的任何建议都会很棒
当我使用IIS添加这样的规则时,它被添加到Web.config:
<rewrite>
<rules>
<rule name="CanonicalHostNameRule">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www'.domain'.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:1}" />
</rule>
</rules>
</rewrite>
在模式部分条件中你有^domain.com$
而我有^www'.domain'.com$