Check out this article, which contains several different options for preventing duplicate URLs on your ASP.NET site: Methods for preventing duplicate URLs in your Site . I have summarized the various methods below, but will review an article for more in-depth treatment, as well as a demo of ASP.NET.
Issuing persistent redirects from ASP.NET
You can check the incoming URL for each request in the event handler Global.asax Application_BeginRequest. If the URL is missing a host www., you can add it and make a permanent redirect to the new URL.
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Request.Url.Authority.StartsWith("www"))
return;
var url = string.Format("{0}://www.{1}{2}",
Request.Url.Scheme,
Request.Url.Authority,
Request.Url.PathAndQuery);
Response.RedirectPermanent(url, true);
}
URL- URL- IIS 7
IIS7 Microsoft URL Rewrite Module, Web.config. , GoDaddy, , IIS7 ( , ) URL. .
, , :
<configuration>
...
<system.webServer>
<rewrite>
<rules>
<rule name="Canonical Host Name" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^yoursite\.com$" />
</conditions>
<action type="Redirect" url="http://www.yoursite.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
- URL-, ISAPI_Rewrite. , GoDaddy , . .
, www., , , , URL.
URL, <link> <head> -. , : <head> -, , URL-:
<link rel="canonical" href="canonical_url" />
View/Source Stackoverflow.com, <link>. , URL- - , www.yoursite.com/foo.aspx yoursite.com/foo.aspx .
!