Point Multiple Domain Names to One Website: Server Side Redirect in ASP.NET

Point Multiple Domain Names to One Website: Server Side Redirect in ASP.NET

Introduction

Chances are, there are several different URLs that point to the same content on your website. For example, the URLs https://yoursite.com, https://yoursite.com/default.aspx, https://www.yoursite.com, or https://www.yoursite.com/default.aspx are all likely valid URLs that results in the same content, namely the homepage for yoursite.com. While having four different URLs reference the same content may not seem like a big deal, it can directly impact your website's search engine placement and, consequently, it's traffic. To a search engine, those four different URLs represent four different pages, even though the all produce the same content.

To understand how allowing duplicate URLs in your website can affect your search engine placement, first understand that search engines base a page's placement in the search results based, in part, on how many other websites link to the page. Now, imagine that there are 1,000 web pages from other websites that link to your homepage. You might conclude, then, that a search engine would rank the importance of your homepage based on those 1,000 links. But consider what would happen if 25% of those links linked to https://yoursite.com, 25% to https://yoursite.com/default.aspx, and so on. Rather than your homepage reflecting 1,000 inbound links, instead the search engine assumes there are only 250 links to https://yoursite.com, only 250 links to https://yoursite.com/default.aspx, and so on. In effect, redundant URLs can dilute your search engine ranking.

A key tenet of search engine optimization is URL normalization, or URL canonicalization. URL normalization is the process of eliminating duplicate URLs in your website. This article explores four different ways to implement URL normalization in your ASP.NET website. The code provided at the bottom handles adds consistency to your website URLs via: i) HTTP to HTTPS re-direction ii) Always have www iii) 301 Permanent Redirects from non-primary domains (i.e. .ca -> .com). 

Content Duplication 

Duplicate content on your own website, where different web addresses ("URLs") on your site display identical content, can lead to problems in your website's performance in the search engine. When you have two different addresses pointing to the same page, like www.example.com/offers.html and example.com/offers.html, many search engines (or so we are led to believe) will treat those two URLs as two separate pages and websites. 

Removing content duplication makes your website more search engine friendly. To imporve your search engine ranking on Google, you want everyone linking to you to reference a single domain, not a single site loading with multiple domains. If people are liknking to 3 different domains, none of them will appear to be as important as they could have had all the links been attributed to a single web address. If you have already pointed all your domains to your website this way, not to worry, this is why our code includes the 301 Permanent Redirect, which is a simple way to tell search engines that all 3 domains point to the same site, and to add up all the back links together and associate them as a single site. 

The way to deal with it is to redirect all pages using one form of the web address ("URL") to the other form, using what is known as a "301" (or "permanent") redirection code. When the search engines see the redirection along with the 301 code, it will realise that the page specified has been permanently relocated to another address. 

Issuing Permanent Redirects From ASP.NET (Application_BeginRequest in Global.asax)

void Application_BeginRequest(object sender, EventArgs e)
{     
	// Basic SSL Redirection:
	/*
		if (!Request.IsSecureConnection)
		{            
			Response.Redirect("https://" + Request.Url.Host + Request.RawUrl);
		}
	*/
	
	var baseURL = "https://www.domain.com";
	
	// Avoid redirection on localhost (local development)
	if (Request.Url.Authority.StartsWith("localhost", StringComparison.Ordinal))
		return;  


	// Example - If URL already https://www.domain.com then do nothing
	if (Request.Url.Scheme == "https" && Request.Url.Authority == baseURL) 
		return;
  
	// ASP.NET 4 Solution:
	/*
	var url = string.Format("{0}://www.{1}{2}",
			   Request.Url.Scheme,
			   Request.Url.Authority,
			   Request.RawUrl); 


	Response.RedirectPermanent(url, true); 
			   
	// If you are not using ASP.NET 4 you will have to write a few more lines of code 
	// to issue a permanent redirect (see bellow). Do not use Response.Redirect as 
	// that issues a temporary redirect and won't cause the search engines to update 
	// their indexes.
			
	*/
	
	// ASP.NET 3.5 Solution: 
   
	if (!HttpContext.Current.Request.Url.ToString().ToLower().Contains(baseURL))
	{
		HttpContext.Current.Response.Status = "301 Moved Permanently";
		Response.StatusCode = (int)System.Net.HttpStatusCode.MovedPermanently; // 301
		Response.AddHeader("Location", baseURL + Request.RawUrl.ToString()); 
		Response.End();
	} 
}	

References

***



要查看或添加评论,请登录

Richard Harris的更多文章

  • Using Linux on Windows via WSL

    Using Linux on Windows via WSL

    Contents Overview of Windows Subsystem for Linux Setup (including Windows PowerShell Commands for WSL & Linux Shell…

  • Cloud Computing QuickStart Guide

    Cloud Computing QuickStart Guide

    Overview Cloud computing is on-demand access (via the internet) to computing resources — applications, servers…

    2 条评论
  • Software Development & Technology News (01/08/2021 - 25/11/2021 )

    Software Development & Technology News (01/08/2021 - 25/11/2021 )

    Googling for Software Development- What Developers Search For and What They Find · It Will Never Work in Theory Why…

    1 条评论
  • Software Development & Technology News (09/02/2021 - 31/07/2021)

    Software Development & Technology News (09/02/2021 - 31/07/2021)

    Do business leaders know how to evaluate developer success- - ZDNet Will Artificial Intelligence Be the End of Web…

  • Azure Infrastructure | IaaS Day Recap

    Azure Infrastructure | IaaS Day Recap

    Today (17/11/2021) I attended Microsoft's Azure IaaS Day, which was delivered in partnership with Intel. In case you…

  • Microsoft SQL Server

    Microsoft SQL Server

    Introduction MS SQL Server is a Relational Database Management System (RDBMS) developed by Microsoft. It provides GUI…

    1 条评论
  • Custom Software Development: Project Initiation

    Custom Software Development: Project Initiation

    Need a custom app built? I can make your vision a reality! We'd begin with Requirements Gathering, Planning, and…

  • Software Development Life Cycle (SDLC)

    Software Development Life Cycle (SDLC)

    Overview The Software Development Life Cycle (SDLC) is a systematic process that development teams use to produce…

    2 条评论
  • LinkedIn Learning Paths: Computer Science

    LinkedIn Learning Paths: Computer Science

    In my past article Best of LinkedIn Learning: Computer Science, I reviewed the Courses offered by LinkedIn Learning…

  • Glossary of Database Terms

    Glossary of Database Terms

    Use the terms and definitions below to better understand Relational Database concepts. Actors: An actor is a model…

    1 条评论

社区洞察

其他会员也浏览了