简体   繁体   English

RedirectPermanent的正确用法是什么?

[英]What is the correct use of RedirectPermanent?

I am working on an eCommerce site that passes product ids in the query string. 我正在开发一个电子商务网站,该网站在查询字符串中传递产品ID。 I just had to fix an issue where the product page didn't check the status of the product (live or archived) so if the user had a direct link eg a search result, the product would still display even if it had a status of "Archived". 我只需修复产品页面未检查产品状态(实时或存档)的问题,因此如果用户有直接链接(例如搜索结果),即使产品状态为“存档”。

My simple fix was to Response.Redirect("~/Products/Default.aspx"); 我的简单修复是Response.Redirect("~/Products/Default.aspx"); if the status was not "Live". 如果状态不是“实时”。

Should I use RedirectPermanent in this situation even if it is possible the product may come back online? 在这种情况下,我是否应该使用RedirectPermanent ,即使产品可能重新上线?

I found that as a general rule, I only do 301 redirects whenever an actual resource/page has moved, for example when reorganizing content on a web site. 我发现作为一般规则,每当实际资源/页面移动时,我只会执行301重定向,例如在重新组织网站上的内容时。

It's almost impossible to correct a 301 made by error - browsers tend to remember 301 redirects, therefore an url which is permanently redirected cannot be used again. 几乎不可能纠正错误造成的301 - 浏览器往往会记住301重定向,因此永久重定向的网址不能再次使用。

In your particular case, maybe a product was archived by mistake? 在您的特定情况下,可能是产品被错误存档了? All the visitors who visited the product's page and got 301 redirected won't be able to see the product's page, even if the product gets un-archived . 访问产品页面并获得301重定向的所有访问者将无法看到产品页面,即使产品未归档也是如此

As to search engines, you may display a different content for archived products, and you may want to appear it differently in your sitemap.xml (different priority, or not at all), or you may exclude it from being indexed ( robots.txt or by using a robots meta ). 对于搜索引擎,您可能会为已存档的产品显示不同的内容,并且您可能希望在sitemap.xml显示不同的内容(不同的优先级,或根本不显示),或者您可以将其排除在索引之外( robots.txt或者使用机器人元 )。

IMO neither. IMO也不是。 You should display a page with the name of the product, and a message that it's no longer available. 您应该显示一个包含产品名称的页面,以及一条不再可用的消息。 Redirect-on-error is very annoying behavior and should be avoided. 重定向错误是非常烦人的行为,应该避免。

You might also want to mark the document so it doesn't get indexed by search machines. 您可能还希望标记文档,以便搜索机器不对其编制索引。 Something like: 就像是:

<META NAME="ROBOTS" CONTENT="NOINDEX">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM