开发者

301 Redirect using Response Header fails to redirect properly

开发者 https://www.devze.com 2023-03-31 08:37 出处:网络
I\'m attempting to implement a 301 redirect for purposes of url rewriting/SEO optimization. I\'m performing these redirects within a module of my VB.NET website.

I'm attempting to implement a 301 redirect for purposes of url rewriting/SEO optimization. I'm performing these redirects within a module of my VB.NET website.

When I specify a new location in the header it always appends the new location onto the existing url instead of completely replacing it or using a relative path. So instead of a nice URL I get a co开发者_如何学编程mbination of both:

http://site.com/productList.aspx?id=123&fid=123&mid=123http://site.com/store/books/

Here is the code that I'm using for the redirect:

httpContext.Response.Status = "301 Moved Permanently"
httpContext.Response.AddHeader("Location", "http://site.com/store/books")
httpContext.Response.End()

I've attempted to use relative ~/ paths with no success. I'm guessing that I'm doing wrong that is very simple. Please help! Thanks in advance.


Are you trying to do this after ASP.NET has already started filling the response buffer? Try calling Response.Clear() first.


The code you posted worked fine for me.

You can try to use the RedirectPermanent method.

0

精彩评论

暂无评论...
验证码 换一张
取 消