简体   繁体   English

REST资源的规范URL

[英]Canonical URLs for REST resources

With plain-old webpages, if you have duplicate content in two locations, you can flag one as 'canonical' so web crawlers and such know that this is just another reference to a resource and explicitly defines the URL of the 'true' location for the content. 对于普通的网页,如果您在两个位置有重复的内容,您可以将其标记为“规范”,以便网络抓取工具知道这只是对资源的另一个引用,并明确定义了“真实”位置的网址内容。 This is done by using a link tag in the HTML <head> tags of the non-canonical page pointing to the original. 这是通过在指向原始的非规范页面的HTML <head>标记中使用链接标记来完成的。

<link rel="canonical" href="http://www.example.com/the-real-url-of-this-content.php>

In the realm of RESTful web services: 在RESTful Web服务领域:

  1. Is this needed, recommended, or not advisable to do? 这是需要的,推荐的还是不可取的?
  2. Is Canonical only a construct for HTML to flag content for search engines? Canonical只是用于标记搜索引擎内容的HTML构造吗?
  3. If needed, how is the same accomplished with HTTP headers? 如果需要,如何使用HTTP标头完成相同的操作? I'm not return HTML (just a JSON object) so the link tag makes no sense... 我没有返回HTML(只是一个JSON对象)所以链接标签没有意​​义......
  4. Does it matter whether or not there is more than one URLs for a unique resource in REST REST中的唯一资源是否有多个URL是否重要?

RFC 6596 potentially answers this. RFC 6596可能会回答这个问题。

  1. Hard to say. 很难说。
  2. It's a generic link relation, but it has been "invented" by Google. 它是一种通用的链接关系,但它已被谷歌“发明”。
  3. See the spec (you could use the HTTP "Link" header field as well). 请参阅规范(您也可以使用HTTP“链接”标头字段)。
  4. No, it does not matter; 不,没关系; but avoiding multiple URIs for the same thing of course is a good idea no matter what. 但是当然,为了同一件事避免多个URI是一个好主意,无论如何。

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

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