gpt4 book ai didi

url-rewriting - 在 URL 中的何处添加 ID?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:33:42 25 4
gpt4 key购买 nike

我正在使用友好的 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

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

最佳答案

ID 位于倒数第二个,而 slug 位于最后一个路径段的一个小优势 (/gallery/photo/529/this-is...):

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

例子

您的问题目前有这个 URL:

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

关于url-rewriting - 在 URL 中的何处添加 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27343034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com