How to redirect page permanently with status code 301?
It is very easy to just write Response.Redirect and redirect user to other page, but you must consider that Response.Redirect method returns 302 status code. 302 status code means that page is moved temporarily. Search engines accept this and page ranking is divided between old and new version of the page. This certainly is not good for search engine optimization (SEO) because we want to concentrate all ranking to one page to get higher position in search results.
Permanent (301) redirection in ASP.NET
To redirect permanently with status code 301, use this snippet:
[ C# ]
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", "/Some-New-Page/");
Response.End();
[ VB.NET ]
Response.Status = "301 Moved Permanently"
Response.AddHeader("Location", "/Some-New-Page/")
Response.End()
Permanent redirection in ASP.NET 4.0
ASP.NET 4.0 brings us new way to do permanent redirection. There is new method Response.RedirectPermanent that simplifies this task. Code could look like this:
[ C# ]
Response.RedirectPermanent("Your-New-URL.aspx", true);
[ VB.NET ]
Response.RedirectPermanent("Your-New-URL.aspx", true)
Related articles:
1. URL Rewriting in ASP.NET
2. HTTP To HTTPS Redirection In ASP.NET