将 URL 关键字存储在数据库中,或导出
如果我有一本名为“哈罗德的紫色蜡笔收藏集”的书,我希望网站 URL 如下所示:
www.site.com/book/harolds-purple-crayon/4324
我需要编写代码来剔除噪音词、特殊字符、长度小于 x 个字符的单词等,从而限制了最终结果等等,但是在编写代码之后,我该怎么办?
我是在每次网站需要 URL 时通过代码运行每个标题,还是使用代码循环遍历所有标题并将结果转储到数据库中并从数据库中提取它们,而不是每次都动态构建它们?
If I have a book named "The Harold's Purple Crayon Collectors Set," I want the website URL to look like this:
www.site.com/book/harolds-purple-crayon/4324
I will need to write code to strip out things like noise words, special characters, words less than x chars long, limiting the final result to y words, etc, but after that code is written, what do I do with it?
Do I run each title through the code every time the URL is needed on my site, or instead, use the code to loop through all my titles and dump the results into a database and pull them from there instead of dynamically building them each time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,最佳实践是将友好 URL 保存到数据库中,并将它们与有关该书的其他信息(在本例中)一起检索。接下来,您所要做的就是使用您生成的字符串和 ID(根据您的示例)重新创建 URL。
The best practice in this case is to save the friendly-URLs to the database and have them retrieved together with other information about that book (in this case). Next, all you have to do is to re-create the URL, using the string you generated and the ID (as per your example).