How do I implement "301 Moved Permanently" programmatically in C#?Place the following C# code in the Page_Load of the old page, i.e. in the page that has moved to the new url:
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", "http://www.newurl.com/page.aspx");
Response.End();
Replace "www.newurl.com/page.aspx" with the url of the new page, i.e. the url of where the page has moved to. Thus, the old page would still exist, but would be directing traffic towards the new page.
As an example, the page "http://www.whadiz.com/oldpage.aspx" has been renamed to "http://www.whadiz.com/newpage.aspx". To keep al traffic directed at "http://www.whadiz.com/oldpage.aspx", we place a "301 moved permanently" on this page's Page_Load event:
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", "http://www.whadiz.com/newpage.aspx");
Response.End();
|
When should I use the "301 Moved Permanently" status code?When moving a website from one domain name to another, or renaming a webpage, those pages might have been indexed by search engines or direct links to those pages might exist. Importent traffic would get lost if you merely rename page. Direct traffic to pages that have been renamed need to be funneled to the correct pages. "301 Moved Permanently" is a good way of achieving this. "301 Moved Permanently" indicates to search engines that a specific url is now longer applicable and that they should rather index the new url. "301 Moved Permanently" is also importent to transfer pagerank from the old url to the new url when optimizing for Google. |
What other ways of implementing "301 Moved Permanently" exist?"301 Moved Permanently" can be implemented directly in IIS via settings, or in Apache via an .htaccess file. The programmatic approach is useful when renaming pages, but other approaches should be considered when moving whole websites from one domain name to another. |