URL 命名约定

发布于 2024-09-05 03:12:13 字数 1007 浏览 3 评论 0原文

所以,这可能是一罐蠕虫。但我很好奇你的做法是什么?

例如,假设您的网站包含以下需求(非常基本):

  1. 登陆页面
  2. 事件的信息页面(静态)
  3. 该事件的地点列表(动态)
  4. 每个地点的信息页面

话虽如此,如何你会设计你的网址吗?

通常,我会执行以下操作:

www.domain.com/ - 登陆页面 [也可通过 www.domain.com/home 访问] www.domain.com/event - 活动信息页面 www.domain.com/places - 所有地点的列表 www.domain.com/places/{id} - 地点信息页面

现在,有一个问题。从语法上来说,我在将 url 中的给定位置引用为复数时遇到了一个难题。这样做不是更有意义吗:

www.domain.com/place/{id} 相对于 www.domain.com/places/{id}

在某些框架中,默认情况下您需要遵循一个约定(例如 ASP.NET MVC)。是的,您可以定义自定义路由以将 /place/{id} 路由到 PlacesController。然而,我只是想在讨论中保持这个有点抽象。

话虽如此,让我们看看,例如在您网站的另一个页面上,您有一个链接,单击该链接时,将打开一个填充有地点信息的模式弹出窗口。你把这些信息放在哪里?

我们可以使用这样的内容:

www.domain.com/ajax/places/{id} 或者 www.domain.com/places/{id} 并根据请求标头提供服务(即,如果请求 JSON,则返回 JSON?}。

最后,出于 SEO 原因,通常我使用与给定资源关联的 slug。因此,像这样的:

www.domain.com/ajax/places/{id}/london

伦敦只是为了 SEO 原因而在链接上添加装饰,这听起来合理吗

?我已经使用了一段时间,我只是想看看其他开发人员在做什么,或者我是否处理不当,

谢谢!

So, this may be a can of worms. But I'm curious what your practices are?

For example, let's say your website consists of the following needs (very basic):

  1. A landing page
  2. An information page for an event (static)
  3. A listing of places for that event (dynamic)
  4. An information page for each place

With that said, how would you design your URLs?

Typically, I'd do something like the following:

www.domain.com/ - landing page [also accessible via www.domain.com/home]
www.domain.com/event - event information page
www.domain.com/places - listing of all places
www.domain.com/places/{id} - place information page

Now, here's a question. Just grammatically speaking, I have a hangup of referring to a given place in a url as being plural. Shouldn't it make more sense to go with this:

www.domain.com/place/{id}
as opposed to
www.domain.com/places/{id}

In some frameworks, you have a convention to follow (for example, ASP.NET MVC) by default. Yes, you can define custom routes to have /place/{id} route to the PlacesController. However, I'm just trying to keep this a bit abstract in discussion.

With that being said, let's see for instance on another page of your site, you have a link, that when clicked, would open a modal popup populated with place information. Where you place that information?

We could go with something like this:

www.domain.com/ajax/places/{id}
OR
www.domain.com/places/{id} and serve based on the request header (that is, if requesting JSON, return JSON?}.

Finally, for SEO reasons, typically I use a slug associated with a given resource. So, something like such:

www.domain.com/ajax/places/{id}/london

Where london is only there to add decoration to the link for SEO reasons. Is this sound?

I ask all of these questions, because these are practices that I've been using for awhile, and I'd just like to see what other developers are doing or if I'm approaching things incorrectly.

Thanks!

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

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

发布评论

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

评论(1

眼泪淡了忧伤 2024-09-12 03:12:13

我喜欢在页面顶部使用面包屑 URL,因此当您向左移动时,每个级别都应该更加通用。

我反对 SEO 标签,因为它们具有误导性、令人恼火且不必要。

用户应该知道何时拥有持久 URL 以及何时拥有动态结果。这 '?'对此提供了一个很好的指示。这就是说,听起来虽然你的地名是动态的,但返回的数据仍然有持久性,对吗?如果用户将 URL 修剪为 www.domain.com/place/ 那就太好了,他们可以以引导方式浏览地点。

我将其称为位置,因为当您登陆页面时,它是一个特定的位置,除此之外,大多数用户不会注意到这一点。我记得听过“简洁是智慧的灵魂”,所以我认为 Polonious 会同意这条领带应该去掉 's'。

I like using the URL for breadcrumbs at the top of a page, so each level should be more general as you move left.

I am opposed to the SEO slugs because they are misleading, irritating, and unnecessary.

Users should know when they have a persistant URL and when they have dynamic results. The '?' provides a good indication of this. This said, it sounds though your place names are dynamic, there is still a persistence to the data that comes back, right? It would be nice if the user pruned the URL to www.domain.com/place/, they good browse places in a guided fashion.

I'd call it place, because when you land on a page it is a specific place, and besides that is not something most users are eben going to notice. I remember hearing "brevity is the soul of wit", so I think Polonious would agree the tie goes to dropping the 's'.

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