0
我想重定向非www网站到www,但是当我在我的web.config中添加重定向规则或在我的Global.asax中显示该页面不是正确重定向。我试图这些事情在同一时间一个:在web.config中重定向非www到www结果在页面没有正确重定向
<rewrite>
<rules>
<rule name="CanonicalHostNameRule" enabled="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="testdomain\.com$" />
<add input="{HTTP_HOST}" pattern="^www\.testdomain\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.testdomain.com/{R:1}" />
</rule>
</rules>
</rewrite>
我也内Application_BeginRequest
注意试过这种从Global.asax中的重定向规则。
if(HttpContext.Current.Request.Url.ToString().ToLower().Contains("http://testdomain.com"))
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location",
Request.Url.ToString().ToLower().Replace("http://testdomain.com", "http://www.testdomain.com"));
}
我的Default.aspx和Default.aspx.cs页面没有代码吧.. 任何想法的家伙在那里实际的问题可能是。
是我使用的一件事。我首先尝试了web.config ruie。然后我尝试了global.asax – dnts2012