我已经阅读了一些关于不同 HTTP 重定向状态代码优点的文档,但这些文档都非常以 SEO 为中心。我现在遇到了搜索引擎不考虑的问题,因为相关网站的部分不可公开查看。
但是,我们确实希望我们的网站在元数据方面尽可能准确/有用,特别是出于可访问性的原因。
现在,我们的应用程序采用第三方提供的外部链接,并将它们路由到带有免责声明的反欺骗页面。由于此重定向器页面也可以通过 Ajax 调用有效地嵌入到某些星座中,因此我们还希望从引用者中删除任何查询参数(出于隐私目的;目标站点无权找出用户之前访问过哪个内部页面) .
为此,确认按钮会触发服务器端脚本,该脚本又会重定向(而不仅仅是为用户打开页面)。
这就是为什么我们的反欺骗免责声明页面最终会触发重定向。
问题是:
我使用的状态代码实际上有什么区别吗?非典型浏览器(例如屏幕阅读器)关心吗?如果是这样,此类重定向的最佳实践是什么?语义上最合理的,如果你愿意的话?在我看来,他们都不同程度地不真诚。
我正在考虑 302 - 但因为尝试为该页面添加书签是没有意义的(它受 crsf token 保护),所以 301 可能也没有什么坏处,不是吗?所以我想知道是否有理由让我更喜欢其中一个而不是另一个。
最佳答案
嗯。 Here's the list. 301 听起来不错(强调我的):
The requested resource has been assigned a new permanent URI and any future references to this resource SHOULD use one of the returned URIs. Clients with link editing capabilities ought to automatically re-link references to the Request-URI to one or more of the new references returned by the server, where possible.
302 不符合我的观点:
The requested resource resides temporarily under a different URI
但是,我最喜欢的是 303 查看其他
:
The response to the request can be found under a different URI and SHOULD be retrieved using a GET method on that resource. This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource. The new URI is not a substitute reference for the originally requested resource.
但这可能非常罕见(我从未见过它在野外使用过),以至于某些客户可能无法理解它 - 这将使您对最大兼容性的渴望变得毫无意义。 301 可能是最接近的选择。
关于redirect - 非SEO反欺骗外部链接重定向: Status code?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2461607/