If you have done SEO work, you know that Search Engines would penalize my site if both http://www.mycsharpcorner.com and http://mycsharpcorner.com/ requests returned a 200 OK code in the HTTP header. Why? Because from a Search Engine's spider point of view, there are 2 sites, one with the www prefix, and one without it, yet in reality they the same site. So what’s wrong if the Search Engine thinks
that way? Well, it leads it to think one of the two sites is showing duplicate content! This would raise a flag with Google’s “duplicate filter” as its ears would point up to the smell of duplicate content. What follows is that your page rankings get hurt once you are tagged a duplicate. Moreover, you suffer rankings split between two sites rather than one.
The solution for this is to do a 301 Redirect. I looked around the net, and there seems to be many articles written about 301 Redirects. Here is a solution that shows up a lot:
Page_Load(object sender, EventArgs e)
"301 Moved Permanently"
For my ASP.NET site, I needed something general, not in each page load event, but for the whole site, so I don’t have to worry about it ever again. So here is what I’ve done:
In my Global.asax file (You can add this to your site from Visual Web Developer or Visual Studio by selecting File->New), In the Application_BeginRequest event, I added a call to the following code:
"301 Moved Permanently";
The above code allows 301 redirects from any entry point to the site. Next I tested my site using this free tool: http://www.rexswain.com/httpview.html , and when I typed http://www.mycsharpcorner.com I got a 200 OK in the HTTP header, but if I type http://mycsharpcorner.com/ then I got a 301 Moved Permanently code, where before the modification, I got 200 OK on both requests. The new result means the Search Engines will consider both urls to point to the same site, so all page rankings will add up regardless of the entry point. Google spider, are you reading this?