问题描述
想象一下,您有一组以漂亮的树状层次结构组织的产品类别,并且您想提供可破解的 url 来浏览这些类别.你可以这样做
/catalog/categorya/categoryb/categoryc
然后,您可以很容易地找出应该列出产品的类别(请注意,需要完整的 URL,因为您可能拥有名称相同但位于层次结构中不同位置的类别)
现在在其中添加产品信息的好方法是什么?举个例子,你想显示这个类别的产品 Oblivion
/catalog/games/consoles/playstation/adventure
在网址末尾添加产品很诱人
/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
也没有那么好,你会(即使它不太可能成为问题)限制自己拥有一个名为 product
的类别到目前为止,后缀解决方案看起来是我能想到的最用户友好的方法,但我不喜欢必须使用扩展程序
您对此有何看法?
深径让我厌烦.他们是可怕的分享.
/product/1234/oblivion --> 直接页面/product/oblivion -->/product/1234/oblivion 如果遗忘是一个独特的产品,--> ~ 消歧页面,如果遗忘不是一个独特的产品./product/1234/notoblivion ->/product/1234/oblivion/categories/79/adventure --> 游戏机冒险游戏/categories/75/games --> 主机游戏页面/categories/76/games --> 游戏机游戏页面/categories/games --> 消歧义页.否则,长网址虽然看起来可以破解,但需要您正确获取所有节点元素才能破解它.
以 php.net
php.net/str_replace --> 转到http://nz2.php.net/manual/en/function.str-replace.php而且这个模型非常容易被破解,人们一直盲目地使用它.
注意:.html 后缀被 W3C 视为功能上毫无意义和多余的,应避免在 URL 中使用.
http://www.w3.org/Provider/Style/URI
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?
Deep paths irk me. They're hideous to share.
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
这篇关于你会如何设计一个可破解的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!