0

I've seen websites like google and facebook redirect from "facebook.com" or "www.facebook.com" to "http://www.facebook.com" versions of their website. How can I redirect like that when people first visit my website?

This is my code so far:

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);
}
user3912889
  • 59
  • 2
  • 6

1 Answers1

0

I use the URL Rewriter for this.

<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>

You can read more about Url Rewrite rules at IIS 7 Url Rewrite Rules for SEO and Security.

Erik Philips
  • 53,428
  • 11
  • 128
  • 150