MVC 站点上项目的 URL:使用项目 ID、项目标题,还是两者都使用?

发布于 2024-12-09 19:06:57 字数 440 浏览 0 评论 0原文

我正在使用 ASP.NET MVC 开发一个网站。该网站将类似于 StackOverflow,因为用户提交的项目将具有数字 ID 和文本标题。

现在我在想如何设计“商品详情”页面的URL路由系统。我曾想过单独使用 id(如 http://www.mysite.com/items/1234)或单独使用标题(如 http://www.mysite.com/items/1234)。 com/items/how-to-foobarize-a-fizzbuzz)。然而,我看到 StackOverflow 使用它们来代替它们(如 http://www.mysite.com/items/1234/how-to-foobarize-a-fizzbuzz 中)。

那么哪一种是最好的方法呢?在 URL 中同时使用 id 和 title 有什么意义呢?这不是多余的吗?

I am developing a web site using ASP.NET MVC. The site will be similar to StackOverflow in that there will be user submitted items that will have a numeric id and a textual title.

Now I am thinking how to design the URL routing system for the "item details" pages. I had thought of using the id alone (as in http://www.mysite.com/items/1234) or the title alone (as in http://www.mysite.com/items/how-to-foobarize-a-fizzbuzz). I see however that StackOverflow uses instead both of them (as in http://www.mysite.com/items/1234/how-to-foobarize-a-fizzbuzz).

So which one is the best approach? And what is the point of using both the id and the title in the URL? Isn't this redundant?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酸甜透明夹心 2024-12-16 19:06:57

是的,同时拥有 ID 和标题(通常称为 slug)是多余的,但从 SEO 和 UX 的角度来看,它都很酷。

不过,个人不太喜欢这里的做法。我似乎无法理解为什么 ID 与带有正斜杠的 slug 分开(/7754456/urls-for-item...)。对我来说,每个部分都意味着某种层次结构,因此破折号会更合适/7754456-urls-for-item...)。但这只是我。

Yes, having both ID and title (which is most often called slug) is redundant, but it's cool both from SEO and UX standpoints.

There's one personal dislike about how it's done here on SO, though. I can't seem to understand why an ID is separated from a slug with a forward slash (/7754456/urls-for-item...). To me, each segment implies some sort of hierarchy, so dash will be more appropriate /7754456-urls-for-item...). But that's just me.

如若梦似彩虹 2024-12-16 19:06:57

使用这种形式的标题(通常称为“slug”)的优点基本上就是 URL 的可读性。但是,如果您没有对标题实施唯一性约束,那么这不一定足以识别记录。因此,当两者都使用时,ID 可以供服务器实际进行查找,而 slug 则可供人们读取。

The advantage of using the title in that form (usually referred to as a "slug") is basically just that of URL readability. However, if you are not enforcing a uniqueness constraint on your titles then this will not necessarily be adequate to identify a record. Therefore, when both are used, the ID can be there for the server to actually to do the lookup and the slug is there for humans to read.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文