【问题标题】:Where to add the ID in a URL?在 URL 中的何处添加 ID?
【发布时间】:2014-12-07 13:21:04
【问题描述】:

我正在使用友好的 URL,如下所示:

http://localhost/gallery/photo/this-is-a-url-friendly-photo-caption

在友好 URL 上,我需要添加照片的 ID,但环顾四周,我看到了将 ID 添加到友好 URL 的两种方式,pre 和 post,就像这样

http://localhost/gallery/photo/this-is-a-url-friendly-photo-caption.529

http://localhost/gallery/photo/529/this-is-a-url-friendly-photo-caption

使用一种方式有优势吗?还是只是偏好/个人品味的问题?

【问题讨论】:

    标签: url-rewriting seo url-design


    【解决方案1】:

    将 ID 放在倒数第二个,将 slug 放在最后一个路径段的一个小优势 (/gallery/photo/529/this-is…):

    在某些情况下,URL 可能会被截断,for example by a line break in plain text emails。如果 ID 位于(通常很长的)slug之前,则 ID 保持完整并且 URL 可以继续运行的可能性更高(假设您重定向到带有 slug 的规范变体)。

    示例

    您的问题目前有这个网址:

    https://stackoverflow.com/questions/27343034/seo-friendly-url-where-to-add-the-id

    当它像那样被切断时(= ID 保持不变),它会重定向到规范变体并且用户很高兴:

    https://stackoverflow.com/questions/27343034/seo
    -friendly-url-where-to-add-the-id

    但是当它被这样切断时(= 不同的 ID),用户就不那么高兴了(因为链接指向不同的页面):

    https://stackoverflow.com/questions/273430
    34/seo-friendly-url-where-to-add-the-id

    【讨论】:

      猜你喜欢
      • 2021-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多