万无一失的 URL 独特标题

发布于 2024-09-17 23:23:00 字数 355 浏览 12 评论 0原文

在我的应用程序 UI 中,如果可能的话,希望避免在 url 中使用 ID 号,因此最好的方法是创建对 url 模式有效的标题的唯一版本。

所以做同样的事情,但因为你允许重复的问题,所以他们在 URI 中有 id!

http://stackoverflow.com/questions/3637971/how-to-edit-onchange-attribute-in-a-select-tag-using-jquery

Wordpress 也实现了此类功能,

我的问题是:

实现此目的的最佳方法是什么,坚持 URI RFC 并让搜索引擎满意

Within my application UI want to avoid id numbers within the urls if possible so the best way to do this would be to create a a unique version of the title that's valid for url schemas.

SO do a something the same but as the you allow duplicate questions they have the id within the URI!

http://stackoverflow.com/questions/3637971/how-to-edit-onchange-attribute-in-a-select-tag-using-jquery

Wordpress have implemented such features as well

my question is:

What's the best way to accomplish this, sticking to the URI RFC as well as keeping search engines happy.

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

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

发布评论

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

评论(3

单调的奢华 2024-09-24 23:23:00

Drupal Path/Pathauto 模块执行此操作,因此我会检查该实现。为了快速命中,如果有标题减少为重复项:

CaseySoftware is awesome
CaseySoftware is awesome!

它们将变成:

caseysoftware-is-awesome
caseysoftware-is-awesome-0

您肯定需要删除标点符号,但您可能想对“a,the,is”等常见文章执行相同的操作。

The Drupal Path/Pathauto modules do this, so I'd check that implementation. For a quick hit, if there are titles that reduce to duplicates:

CaseySoftware is awesome
CaseySoftware is awesome!

They would become:

caseysoftware-is-awesome
caseysoftware-is-awesome-0

You will definitely need to scrub out punctuation, but you may want to do the same to common articles like "a, the, is".

薄荷→糖丶微凉 2024-09-24 23:23:00

为了让搜索引擎满意,

您应该在头脑中使用它:

<link rel="canonical" href="http://yoursite.com/page/uniqueTitle/"/>

这将告诉搜索引擎具有该特定规范名称的所有页面都是相同的。

例如,此页面有以下行:

<link rel="canonical" href="http://stackoverflow.com/questions/3637990/foolproof-unique-title-for-urls">

如果更改标题,该值将保持不变。这就是搜索引擎真正知道它们都是同一页面的方式。

如何生成

至于如何生成这些 URL,您应该坚持使用小写字母数字字符 ([a-z0-9]) 并将空格替换为“-”。

To keep search engine happy

You should use this in your head :

<link rel="canonical" href="http://yoursite.com/page/uniqueTitle/"/>

This will tell search engine that all page that have that specific canonical name are the same.

For example, this page has the following line :

<link rel="canonical" href="http://stackoverflow.com/questions/3637990/foolproof-unique-title-for-urls">

If you change the title, that value will stay the same. This is how search engine really know it's all the same page.

How to generate

As for how those URL are generated, you should stick to the lower case alphanumeric characters ([a-z0-9]) and replace space with "-".

硪扪都還晓 2024-09-24 23:23:00

“友好的 URL — 可能是良好 URL 结构的全部要素” 是一篇不错的文章关于该主题,它包括一个简短的 Python 示例实现。

为了使 URL 真正唯一,而不必在任何地方使用数字 ID,我会尝试生成新 URL,查看它是否已经存在(不应经常出现),并且只有在存在时,才附加一个简短的序列号在最后。

"Friendly URLs — Possibly all of what makes a good URL structure" is a nice article about that topic, and it includes a short example implementation in Python.

To make the URLs really unique without having to use a numeric ID everywhere, I'd try to generate my new URL, see if it already exists (shouldn't occur very often), and only if it does, append a short sequence number at the end.

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