0

I have a page in an MVC asp.net project that has gone away. We've renamed the URL to something entirely different.

The problem is other sites still link to that particular url.

We could blank out the html for the url in question and do a meta refresh or a javascript script call to take them to the new page, but that doesn't really fit our model.

I could add another route, and let asp.net take care of it, but hardcoding routes for urls to be forwarded seems like bad practice. I could also edit the asp.net page and use a response.redirect, but there's no real page in existence since this is a light CMS...

How SHOULD I redirect a user from a url landing page to a different landing page using best practice? We don't need the user to see a "this page has moved" or anything like that as part of the requirement.

Phil Murray
  • 6,396
  • 9
  • 45
  • 95
bmccall1
  • 79
  • 1
  • 1
  • 7

3 Answers3

3

It looks like you need to return an HTTP 301 status code, Moved Permanently. This answer appears to outline general approaches in asp.net MVC.

For example:

public ActionResult Page()
{
    Response.Status = "301 Moved Permanently";
    Response.AddHeader("Location","http://example.com");
}

This will result in returning the mentioned HTTP 301, which will be followed by search engines and user's browsers transparently.

Community
  • 1
  • 1
Chris Alexander
  • 1,212
  • 14
  • 19
0

301 redirect is the best way to do it because it preserves your rank in search engines. You can do it with this script:

NOTE: Put this code between a script runat="server" tag.

private void Page_Load(object sender, System.EventArgs e) {
    Response.Status = "301 Moved Permanently";
    Response.AddHeader("Location","http://example.com");
}
Ketchuz
  • 45
  • 1
  • 5
  • Its not APS.NET, so no _runat="server" tag_ – Satpal Jan 31 '14 at 22:12
  • Take a look on this guide by Microsoft. It has code snippets in four languajes: http://msdn.microsoft.com/en-us/library/dd322042(v=vs.100).aspx – Ketchuz Jan 31 '14 at 22:19
  • So mate can you write this code in an console c# application. Will that work. Only Language doesn't matter. You need to know framework also – Satpal Jan 31 '14 at 22:21
0

If your old URL is an ASP.NET MVC action, use RedirectPermanent, it sends the browser an HTTP 301 (Moved Permanently) status code.

Use RedirectPermanent if the resource has been moved permanently and will no longer be accessible in its previous location. Most browsers will cache this response and perform the redirect automatically without requesting the original resource again.

public ActionResult MyAction()
{
    return RedirectPermanent("<new url>");
}
Alon Gubkin
  • 56,458
  • 54
  • 195
  • 288