C# 包括;www";在网站改变一切?
我见过像谷歌和facebook这样的网站从“facebook.com”或“www.facebook.com”重定向到他们网站的“”版本。当人们第一次访问我的网站时,我怎么能这样重定向 这是我目前的代码:C# 包括;www";在网站改变一切?,c#,asp.net,redirect,C#,Asp.net,Redirect,我见过像谷歌和facebook这样的网站从“facebook.com”或“www.facebook.com”重定向到他们网站的“”版本。当人们第一次访问我的网站时,我怎么能这样重定向 这是我目前的代码: var link = HttpContext.Current.Request.Url.AbsoluteUri.ToLower(); var path = HttpContext.Current.Request.Url.AbsolutePath; if (link.StartsWith("http
var link = HttpContext.Current.Request.Url.AbsoluteUri.ToLower();
var path = HttpContext.Current.Request.Url.AbsolutePath;
if (link.StartsWith("http://www") == false)
{
Response.Redirect("http://www.arcadeLegend.com" + path);
}
我用这个
<rule name="Redirect to www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="domain.com" />
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:0}" />
</rule>
<rule name="HTTP Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://www.domain.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
.太棒了!我只是把它添加到web.config?很好!