你会如何设计一个可破解的网址

发布于 2024-07-09 12:44:32 字数 953 浏览 9 评论 0原文

想象一下,您有一组以良好的树形层次结构组织的产品类别,并且您希望提供可修改的 URL 来浏览这些产品类别。 您可以这样做,

/catalog/categorya/categoryb/categoryc

然后您可以很容易地找出应该列出产品的类别(请注意,需要完整的 URL,因为您可以拥有具有相同名称但位于层次结构中不同位置的类别)

现在会是什么在其中添加产品信息的好方法是什么? 举个例子,您想要显示此类别的产品 Oblivion

/catalog/games/consoles/playstation/adventure

很容易将产品添加到 url 末尾

/catalog/games/consoles/playstation/adventure/oblivion

,但一旦您这样做,您就无法知道其类别或产品是否被称为遗忘。 我个人认为,不被迫添加后缀(例如 .html)

/catalog/games/consoles/playstation/adventure/oblivion.html

将是最好的解决方案,并使用某种前缀,例如

/catalog/games/consoles/playstation/adventure/product:oblivion

您也可以添加某种触发器,例如

/catalog/games/consoles/playstation/adventure/PRODUCT/oblivion

不太好,您会(即使它非常好)不太可能会成为问题)限制自己使用名为产品的类别

到目前为止,后缀解决方案看起来是我从头到尾能想到的最用户友好的方法,但我不喜欢使用扩展程序,

您对此有何看法?

Imagine you had a group of product categories organized in a nice tree hierarchy and you wanted to provide hackable urls to browse these. You could do something like this

/catalog/categorya/categoryb/categoryc

You could then quite easily figure out which category you should list the products for (note that the full URL is needed since you could have categories with the same name but at different locations in the hierarchy)

Now what would be a good approach to add product information in that as well? To give you an example, you wanted to display the product Oblivion for this category

/catalog/games/consoles/playstation/adventure

It's tempting to just add the product at the end of the url

/catalog/games/consoles/playstation/adventure/oblivion

but the moment you do so you loose the ability to know if its category or a product which is called oblivion. I personally feel that not being forced to add a suffix such as .html

/catalog/games/consoles/playstation/adventure/oblivion.html

would be the nicest solution and using some sort of prefix, such as

/catalog/games/consoles/playstation/adventure/product:oblivion

You could also add some sort of trigger like

/catalog/games/consoles/playstation/adventure/PRODUCT/oblivion

not as nice either and you would (even though its very unlikely it would be a problem) restrict yourself from having a category called product

So far a suffix solution looks like the most user-friendly approach that I can think of from the top of my head but I'm not fond of having to use an extension

What are your thoughts on this?

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

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

发布评论

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

评论(9

扬花落满肩 2024-07-16 12:44:32

深邃的道路让我烦恼。 它们很难分享。


/product/1234/oblivion --> direct page
/product/oblivion --> /product/1234/oblivion if oblivion is a unique product, 
                  --> ~ Diambiguation page if oblivion is not a unqiue product. 

/product/1234/notoblivion -> /product/1234/oblivion

/categories/79/adventure -->  playstation adventure games
/categories/75/games -->  console games page
/categories/76/games -->  playstation games page 
/categories/games --> Disambiguation Page. 

否则,长网址虽然看起来可以破解,但需要您正确获取所有节点元素才能破解它。

以 php.net 为例

php.net/str_replace -->  goes to 
  http://nz2.php.net/manual/en/function.str-replace.php

,这个模型非常容易被破解,人们一直盲目地使用它。

注意:W3C 认为 .html 后缀在功能上没有意义并且是多余的,应在 URL 中避免使用。

http://www.w3.org/Provider/Style/URI

Deep paths irk me. They're hideous to share.


/product/1234/oblivion --> direct page
/product/oblivion --> /product/1234/oblivion if oblivion is a unique product, 
                  --> ~ Diambiguation page if oblivion is not a unqiue product. 

/product/1234/notoblivion -> /product/1234/oblivion

/categories/79/adventure -->  playstation adventure games
/categories/75/games -->  console games page
/categories/76/games -->  playstation games page 
/categories/games --> Disambiguation Page. 

Otherwise, the long urls, while seeming hackable, require you to get all node elements right to hack it.

Take php.net

php.net/str_replace -->  goes to 
  http://nz2.php.net/manual/en/function.str-replace.php

And this model is so hackable people use it all the time blindly.

Note: The .html suffix is regarded by the W3C as functionally meaningless and redundant, and should be avoided in URLs.

http://www.w3.org/Provider/Style/URI

jJeQQOZ5 2024-07-16 12:44:32

让我们剖析您的 URL,使其更加 DRY(不重复)。 这就是您要开始的内容:

/catalog/games/consoles/playstation/adventure/oblivion

实际上,冒险类别是多余的,因为游戏可以属于多种类型。

/catalog/games/consoles/playstation/oblivion

接下来让我印象深刻的是,游戏机也不需要了。 将 PC 机和控制台机作为一个小部分来区分可能不是一个好主意。 它们都是各种类型的机器,这样做只是增加了另一个层次的复杂性。

/catalog/games/playstation/oblivion

现在您需要对您的网站做出一些决定。 我建议删除页面上的 playstation 类别,因为游戏可以跨多个平台存在,而且 games 类别也可以存在。 您的网址应如下所示:

/catalog/oblivion

那么如何获取 Playstation 上所有动作游戏的列表呢?

/catalog/tags/playstation+adventure

或者也许

/catalog/tags/adventure/playstation

顺序并不重要。 您还必须确保 tags 是产品的保留名称。

最后,我假设您由于冲突而无法删除根 /catalog 。 然而,如果您的网站很小并且没有很多其他部分,那么请将所有内容减少到根级别:

/oblivion
/tags/playstation/adventure

哦,如果 oblivion 不是一个独特的产品,只需构建一个包含其 ID 的 slug:

/1234-oblivion

Lets disect your URL in order to be more DRY (non-repetitive). Here is what you are starting with:

/catalog/games/consoles/playstation/adventure/oblivion

Really, the category adventure is redundant as the game can belong to multiple genres.

/catalog/games/consoles/playstation/oblivion

The next thing that strikes me is that consoles is also not needed. It probably isn't a good idea to differentiate between PC's and Console machines as a subsection. They are all types of machines and by doing this you are just adding another level of complexity.

/catalog/games/playstation/oblivion

Now you are at the point of making some decisions about your site. I would recommend removing the playstation category on your page, as a game can exist across multiple platforms and also the games category. Your url should look like:

/catalog/oblivion

So how do you get a list of all the action games for the Playstation?

/catalog/tags/playstation+adventure

or perhaps

/catalog/tags/adventure/playstation

The order doesn't really matter. You have to also make sure that tags is a reserved name for a product.

Lastly, I am assuming that you cannot remove the root /catalog due to conflicts. However, if your site is tiny and doesn't have many other sections then reduce everything to the root level:

/oblivion
/tags/playstation/adventure

Oh and if oblivion isn't a unique product just construct a slug which includes it's ID:

/1234-oblivion
热鲨 2024-07-16 12:44:32

这些看起来都很好(除了带冒号的)。

关键是当他们猜错时该怎么办 - 不要将他们发送到 404 - 相反,将你不认识的单词发送到该单词的搜索页面结果 - 如果可以的话那就更好了那里有拼写检查。

Those all look fine (except for the one with the colon).

The key is what to do when they guess wrong -- don't send them to a 404 -- instead, take the words you don't know and send them to your search page results for that word -- even better if you can spell check there.

沐歌 2024-07-16 12:44:32

如果您将不同的部分视为目标,那么产品本身只是另一个目标。
所有目标都应该可以通过 target.html 或仅目标访问。

目录/游戏/控制台/playstation.html
目录/游戏/控制台/playstation

目录/游戏/控制台/playstation/adventure.html
目录/游戏/控制台/playstation/冒险

目录/游戏/控制台/playstation/adventure/oblivion.html
Catalog/games/consoles/playstation/adventure/oblivion

等等以使其保持一致。

我的5分钱...

If you see the different pieces as targets then the product itself is just another target.
All targets should be accessable by target.html or only target.

catalog/games/consoles/playstation.html
catalog/games/consoles/playstation

catalog/games/consoles/playstation/adventure.html
catalog/games/consoles/playstation/adventure

catalog/games/consoles/playstation/adventure/oblivion.html
catalog/games/consoles/playstation/adventure/oblivion

And so on to make it consistent.

My 5 cents...

孤独难免 2024-07-16 12:44:32

一个问题是,您的用户对“以良好的树形层次结构组织的一组产品类别”的概念可能与您的概念相符。
以下是 David Weinberger 的 Google 技术演讲“Everything is Miscellaneous”,其中包含一些关于内容分类的有趣想法:

http ://www.youtube.com/watch?v=x3wOhXsjPYM

One problem is that your user's notion of a "group of product categories organized in a nice tree hierarchy" may match yours.
Here's a google tech talk by David Weinberger's "Everything is Miscellaneous" with some interesting ideas on categorizing stuff:

http://www.youtube.com/watch?v=x3wOhXsjPYM

当爱已成负担 2024-07-16 12:44:32

@Lou Franco是的,这两种方法都需要一个强大的后备机制,并将其发送到某种建议页面或搜索引擎将是很好的候选者

@Stefan,将两者视为目标的问题是如何区分它们(就像我所描述的那样)。 最坏的情况是,您首先访问数据库以查看是否有满足该路径的类别,如果不满足,则检查是否有满足该路径的产品。 问题是,对于每个产品路径,您最终都会对数据库进行无用的调用,以确保它不是一个类别。

@some 是的,分隔符可能是一个可能的解决方案,但 .html 后缀更加用户友好且众所周知。

@Lou Franco yeah either method needs a sturdy fallback mechanism and sending it to some sort of suggestion page or seach engine would be good candidates

@Stefan the problem with treating both as targets are how to distinguish them (like I described). At worst case scenario is that you first hit your database to see if there is a category which satisfies the path and if it doesn't then you check if there is a product which does. The problem is that for each product path you will end up making a useless call to the database to make sure its not a category.

@some yeah a delimiter could be a possible solution but then a .html suffix is more userfriendly and commonly known of.

待天淡蓝洁白时 2024-07-16 12:44:32

我喜欢 /videogames/consolename/genre/title" 并使用 / 的数量来区分类别或产品。我唯一担心的是多(或难以区分)类型。我强烈建议标题上不要扩展您也可以执行类似 videogames(.php)?c=x360;t=oblivion; 的操作,然后猜测缺少的信息,但是我喜欢 / 方法,因为它看起来更简洁。使用标题的第一个字母或只是做视频游戏/控制台/标题/

i like /videogames/consolename/genre/title" and use the amount of /'s to distinguish between category or product. The only thing i would be worried about multi (or hard to distinguish) genre. I highly recommend no extension on title. You could also do something like videogames(.php)?c=x360;t=oblivion; and just guess the missing information however i like the / method as it looks more neat. Why are you adding genre? it may be easier to use the first letter of the title or just to do videogame/console/title/

滥情哥ㄟ 2024-07-16 12:44:32

我的卑微​​经验,虽然与销售游戏无关,但告诉我:

  • 编辑通常不会为这些“鼻涕虫”使用最好的名字,他们没有明智地选择它们。
  • 许多项目(逻辑上)属于多个类别,那么为什么将它们(技术上)限制为单个类别呢?

通过 ids 更好地设计项目 url,(即 /item/435/ )

  • id 是稳定的(由数据库生成,编辑器不可编辑),因此 url 更有可能随着时间的推移不被更改,因为
  • 它们不会公开(或依赖于)数据库中对象的组织,就像 URL 的 Category/item_name 样式一样。 如果您更改底层设计(对象结构)以允许一个项目属于多个类别怎么办? 类别/项目网址突然不再有意义; 您将更改您的网址设计,旧的网址可能不再有效。

标签比类别更好。 也就是说,允许一个项目属于多个类别是比为每个项目分配一个类别更好的方法。

My humble experience, although not related to selling games, tells me:

  • editors often don't use the best names for these "slugs", they don't chose them wisely.
  • many items belong (logically) to several categories, so why restrict them (technically) to a single category?

Better design item urls by ids, (i.e. /item/435/ )

  • ids are stable (generated by the db, not editable by the editor), so the url stands a much bigger chance at not being changed over time
  • they don't expose (or depend on) the organization of the objects in the database like the category/item_name style of urls does. What if you change the underlying design (object structure) to allow an item to belong to multiple categories? the category/item urls suddenly won't make sense anymore; you'll change your url design and old urls might not work anymore.

Labels are better than categories. That is to say, allowing an item to belong to several categories is a better approach than assigning one category to each item.

娇女薄笑 2024-07-16 12:44:32

将两者视为的问题
目标是如何区分它们
(就像我所描述的)。 最坏的情况
场景是你首先击中你的
数据库查看是否有某个类别
满足路径并且如果它
那么你不检查是否有
的产品。 问题是
对于每个产品路径,您将
最终进行了无用的调用
数据库以确保它不是
类别。

所以呢? 确实没有必要在产品和类别之间进行严格区分,尤其是在 URI 中,除非可能需要考虑额外的数据库调用的性能问题。 如果这对您来说真的很重要,请考虑以下两个建议:

  1. 大多数页面浏览量可能是在产品上,而不是在类别上。 因此,首先检查产品将最大限度地减少您需要加倍数据库查找的频率。
  2. 向您的应用添加代码以显示生成每个页面所需的时间,然后使用秒表前往最近的网吧(不是您的内部 LAN!)。 从您的网站中调出一些页面,并计算每个页面调出所需的时间。 减去生成页面所花费的时间。 还比较生成一个数据库查找页面与两个数据库查找页面所需的时间。 然后问问自己,当建立网络连接、生成内容和下载内容总共可能需要 1-2 秒时,您是否需要额外花费 0.05 秒或更少的时间来进行额外的数据库查找,这真的很重要吗? ?

优化重要的地方,例如制作人性化的 URL(如 Chris Lloyd 的回答)。 不要浪费时间试图削减最后可能的百分之一。

the problem with treating both as
targets are how to distinguish them
(like I described). At worst case
scenario is that you first hit your
database to see if there is a category
which satisfies the path and if it
doesn't then you check if there is a
product which does. The problem is
that for each product path you will
end up making a useless call to the
database to make sure its not a
category.

So what? There's no real need to make a hard distinction between products and categories, least of all in the URI, except maybe a performance concern over an extra database call. If that's really such a big deal to you, consider these two suggestions:

  1. Most page views will presumably be on products, not categories. So doing the check for a product first will minimize the frequency with which you need to double up on the database lookups.
  2. Add code to your app to display the time taken to generate each page, then go out to the nearest internet cafe (not your internal LAN!) with a stopwatch. Bring up some pages from your site and time how long each takes to come up. Subtract the time taken to generate the page. Also compare the time taken to generate one-database-lookup pages vs. two-database-lookup pages. Then ask yourself, when it takes maybe 1-2 seconds total to establish a network connection, generate the content, and download the content, does it really matter whether you're spending an extra 0.05 second or less for an additional database lookup or not?

Optimize where it matters, like making URLs that will be human-friendly (as in Chris Lloyd's answer). Don't waste your time trying to shave off the last possible fraction of a percent.

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