Im building a small webshop and have run into a problem. The company which im building this webshop for has a lot of old SEO links pointing to products and categories. They, of course, do not want to loose these inbound links开发者_如何学JAVA and still want value from them. I need to catch an inbound link e.g. www.myshop.com/myproduct.html and relay it with a HTTP 301 to e.g. www.myshop.com/products/ShowProduct/42
Any ideas on how to do this, i did this before in a asp.net webforms with a generic handler, that intercepted all calls, but i cant seem to get that to work.. I need to do this in code, i dont have access to the IIS since its a web hotel. I know all the inbound links.
You could implement the Application_BeginRequest
method to intercept all requests. In this method you can test on the Request.Url
property to determine what to do.
Something like this (in Global.asax.cs):
protected void Application_BeginRequest()
{
if (this.Request.Url.AbsolutePath.EndsWith(".html", StringComparison.OrdinalIgnoreCase))
{
// TODO: Apply logic here.
this.Response.Redirect("/MyUrl/", true);
}
}
This will redirect all requests to *.html to /MyUrl/
精彩评论