Iis 7 在windows server中创建301重定向
我使用IIS管理器中的URL重写部分为我的网站创建Iis 7 在windows server中创建301重定向,iis-7,asp.net-mvc-4,web-config,http-redirect,Iis 7,Asp.net Mvc 4,Web Config,Http Redirect,我使用IIS管理器中的URL重写部分为我的网站创建重定向301,并将搜索引擎和用户从域名.com重定向到www.DomainName.com。在IIS中为此目的创建规则后,它会在web.config文件中生成以下代码: <rewrite> <rules> <rule name="redirect 301" stopProcessing="true"> <match url="^DomainName\.com
重定向301
,并将搜索引擎和用户从域名.com
重定向到www.DomainName.com
。在IIS中为此目的创建规则后,它会在web.config
文件中生成以下代码:
<rewrite>
<rules>
<rule name="redirect 301" stopProcessing="true">
<match url="^DomainName\.com.*" />
<action type="Redirect" url="www.{R:0}" />
</rule>
</rules>
</rewrite>
但这对我不起作用
我的代码中是否存在任何错误,或者我必须使用另一种方法来执行此操作?我在场景4:规范主机名中找到了答案,
为此,我必须创建规范域名
规则,并编写我的主url以将其他形式的url重定向到该规则。
web.config
文件中的代码如下:
<rewrite>
<rules>
<rule name="CanonicalHostNameRule1">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.domainName\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.domainName.com/{R:1}" />
</rule>
</rules>
</rewrite>