【发布时间】:2014-03-19 05:40:23
【问题描述】:
我正在尝试将非 www 网站重定向到 www,但是当我在 web.config 或 Global.asax 中添加重定向规则时,它显示该页面未正确重定向。 web.config 中的重定向规则
<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 页面中没有代码.. 任何想法的家伙,实际问题可能出在哪里。
【问题讨论】:
标签: asp.net .net iis web-config url-redirection