什么是“友好 URL”?

发布于 2024-07-13 06:20:25 字数 1561 浏览 13 评论 0 原文

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

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

发布评论

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

评论(19

仅此而已 2024-07-20 06:20:25

Tim Berners-Lee(WWW 的架构师)写了一篇关于这个主题的精彩文章 10年前。

  • 您的示例是一个错误的 URL,但这不仅仅是因为它同时具有 id 和“slug”(页面标题的缩写、连字符形式)。 从长远来看,将页面标题放入 URL 中是有问题的。内容随着时间的推移而发生变化。 如果您更改了该博客文章的标题,您将被迫在保留旧 URL 或更改 URL 以匹配新标题之间做出选择。 更改 URL 将破坏该页面之前的所有链接; 不更改它意味着您将拥有一个与页面不匹配的 URL。 这对用户来说都没有好处。 最好直接使用www.myblog.com/posts/123

  • 用户通常确实需要键入网址,但更重要的是,有时他们还会编辑现有网址以查找您网站中的其他页面。 因此,拥有可发现的 URL 通常是件好事。 例如,如果我想查看帖子 #124,我可以轻松查看当前 URL,并得出我想查看的页面的 URL 是 www.myblog.com/posts/124。 这种用户友好程度可以为人们寻找所需的内容提供很大帮助。 包含其他信息(例如帖子的主题)可能会使这变得不可能 - 因此它减少了我的探索选项。

  • 忘记搜索引擎优化。 一段时间以来,搜索引擎技术一直在降低 SEO 黑客的效率。 好的内容仍然是王道,从长远来看,您将无法欺骗系统。

Tim Berners-Lee (the architect of the WWW) wrote a great article about this subject about 10 years ago.

  • Your example is a bad URL -- but not just because it has both an id and a "slug" (the abbreviated, hyphenated form of the page title). Putting the page title into your URL is problematic in the long term. Content will change over time. If you ever change the title of that blog post, you'll be forced to choose between keeping the old URL, or changing the URL to match the new title. Changing the URL will break any previous links to that page; and not changing it means you'll have a URL that doesn't match the page. Neither is good for the user. Better to just go with www.myblog.com/posts/123.

  • Users often do need to type a URL, but more importantly, sometimes they'll also edit existing URLs to find other pages in your site. Thus, it's often good to have discoverable URLs. For example, if I want to see post #124, I could easily look at the current URL and figure that the URL for the page I want to see is www.myblog.com/posts/124. That's a level of user-friendliness that can be a big help to people trying to find what they're looking for. Including other information (like the subject of the post) can make this impossible -- so it reduces my exploration options.

  • Forget about SEO. Search engine technology has been reducing the effectiveness of SEO hacks for some time. Good content is still king -- and in the long run, you won't be able to game the system.

洒一地阳光 2024-07-20 06:20:25

对我来说,友好 URL 意味着有人尝试在 URL 中包含语义信息,以使其更适合人类使用。 这是一个有趣的例子,计算机-计算机界面被增强和构建,以形成更好的人机界面。

因此,在您的两个示例中:

  • www.myblog.com/posts/123/this-is-the-name-of-my-blog-post 很友好,因为您已将标题包含在URL - 它告诉您有关该页面的一些信息。
  • www.myblog.com/posts.aspx?id=123 是不友好的,因为它神秘而晦涩:它对数据库来说非常有意义,但对你我来说却毫无意义。

友好的 URL 在某些情况下非常有用,但在其他情况下则毫无用处。 基本上,如果用户要接触它,我会将友好的 URL 创建作为优先事项,而这不仅仅是美观的问题。 如果您可以快速查看并了解各种选项是什么,那么从地址栏返回 URL 就会变得更加容易,此外,如果您“正在跟踪网页中的链接。

将所有这些与 Firefox 3+ 中令人惊叹的栏相结合(其他浏览器中肯定也会出现),当您处理友好的 URL 时,地址栏中的自动完成功能将变得非常强大。

To me, friendly URL means there's been some attempt to include semantic information in the URL to make it more fit for human consumption. It's an interesting example of a computer-computer interface being augmented and built upon to make a better human-computer interface.

So, in your two examples:

  • www.myblog.com/posts/123/this-is-the-name-of-my-blog-post is friendly, because you've included the title in the URL - it tells you something about the page.
  • www.myblog.com/posts.aspx?id=123 is unfriendly because it's cryptic and obscure: it makes perfect sense to a database, but none to you or me.

Friendly URLs are fantastic in some situations and useless in others. Basically, if a user is ever going to be exposed to it, I'd make friendly URL creation a priority, and it's not just a matter of aesthetics. It makes it much easier to get back to URLs from the address bar if you can quickly see and understand what the various options are, plus it makes it more obvious where you're about to go if you're following a link from a web page.

Combine all that with the awesome bar in Firefox 3+ (surely coming in other browsers too), and auto-complete in the address bar becomes incredibly powerful when you're dealing with friendly URLs.

醉态萌生 2024-07-20 06:20:25

关于查询字符串对爬虫的确切影响,似乎有很多相互矛盾的信息,但共识是,拥有多个参数会损害您的搜索引擎优化,因为长查询字符串变量表示动态内容,因此大多数搜索引擎都会有很多不太积极地索引您的页面。

在您的网址中添加一个 slug,例如示例中的 this-is-the-name-of-my-blog-post,也会使您的链接之间比简单的 ID 号更加不同,并在 url 中添加更重要的单词。 这些都是搜索引擎寻找的东西。

就我个人而言,我发现此类 url 更容易在视觉上进行解析,因为使用的标点符号较少,并且查询字符串中的名称-值对可能非常冗长且难以记住。

There seems to be a lot of conflicting information about precisely what effect querystring have on crawlers, but the consensus is that having more than a couple parameters harms your SEO because a long querystring variable indicates dynamic content, and so most search engines will be a lot less aggressive indexing your page.

Adding a slug to your url, such as this-is-the-name-of-my-blog-post from your example, also makes your links more different from one another than a simple id number, and adds more significant words into the url. These are all things that search engines look for.

Personally I find such urls much easier parse visually because there are fewer punctuation characters used, and the name-value pairs in the querystring can be very verbose and hard to remember.

温馨耳语 2024-07-20 06:20:25

关于如何在 URL 中添加不必要的信息是一个很好的观点。

http://stackoverflow.com/questions/522466/what-makes-a-friendly-url

一旦知道了唯一的 id 522466 - 其余的都是无用的,因此它纯粹是为了使 URL 看起来“漂亮”,并为用户提供页面链接到的内容的想法。 但这又产生了另一个问题。 大多数网站不会“验证”URL 的该部分,因此您可以输入 --

http://stackoverflow.com/questions/522466/omg-goatse-bought-by-bill-gates

Yet 它仍会链接到这篇文章。 您可以看到这可能会导致比其价值更多的问题,因为它们可能会被恶意使用。

我觉得 Digg 对此采取了正确的方法。 他们不在 URL 中使用 ID。 在幕后,他们纯粹根据给定的标题从数据库中获取 ID。

http://digg.com/linux_unix/I_Like_Linux_so_my_aunt_sends_me_this_for_Christmas

对我来说,这是完美的网址。 它为我提供了单击链接时感到安全所需的所有信息。

事实上,标题发挥着如此巨大的作用,以至于在挖掘的世界中,人们纯粹基于他们喜欢标题或对其感兴趣而“盲目挖掘”。 如果您的网址看起来很有趣,那么您的网站很可能会获得更多流量。 同时,您将使其变得更加用户友好、更漂亮,搜索引擎将会感谢您。 据我所知,友好的网址对每个人来说都是双赢的。

It's a good point about how your putting unnecessary information in the URL.

http://stackoverflow.com/questions/522466/what-makes-a-friendly-url

Once the unique id 522466 is known - the rest is useless, so it purely serves to make the URL look "nice" and provide the user with an idea as to what the page links to. But this creates another problem. Most sites do not "verify" that part of the URL, so you could put --

http://stackoverflow.com/questions/522466/omg-goatse-bought-by-bill-gates

Yet it will still link to this post. You can see how this may cause more problems than they are worth because they could be used maliciously.

I feel Digg have taken the right approach to this. They do not use IDs in their URLs. Behind the scenes they get the ID from their database purely from the title given.

http://digg.com/linux_unix/I_Like_Linux_so_my_aunt_sends_me_this_for_Christmas

This, for me, is the perfect url. It gives me all the information I need to feel secure in clicking the link.

In fact, titles play such a huge role that, in the world of digg, people "blind digg" purely based on the fact that they like the title, or are interested in it. If your url looks interesting, you may very well be getting more traffic to your site. At the same time you will be making it more user friendly, prettier, and search engines will thank you. As far as I can see, friendly urls are win win for everyone.

ヅ她的身影、若隐若现 2024-07-20 06:20:25

我对你的三个要点的看法:

  • 我想说这不是一个最佳的网址。 我不知道为什么会同时显示帖子标识符和标题。 我的 URL 中根本不包含帖子 ID,仅包含标题和(有时)日期
  • 对于用户来说,越短越好。
  • 搜索引擎会查看网址。 不管有意义与否,他们都这么做。 在 URL 中包含关键字将带来一些 SEO 优势。

My thoughts on your three bullets:

  • I'd say that's not an optimal URL. I have no idea why one would show both the post identifier and title. I don't ever include post IDs in my URLs at all, only titles and (sometimes) dates
  • For users, shorter is better.
  • Search engines look at the url. Whether it makes sense or not, they do. Having keywords in the URL will offer some SEO benefit.
三生池水覆流年 2024-07-20 06:20:25

我碰巧同意你的观点,但是不要告诉任何人。

这只是我的拙见,但对我来说,

http://stackoverflow.com/questions/522466/

http://stackoverflow.com/questions/522466/what-makes-a-friendly-url

是同一页似乎很愚蠢。 我的意思是,我可以看到连字符的问题标题为 URL 提供了一些上下文,但除非您知道该部分是可选的,否则 URL 只会不必要地变长。

I happen to agree with you, but shhh don't tell anyone.

It's just my humble opinion, but it seems silly to me that

http://stackoverflow.com/questions/522466/

and

http://stackoverflow.com/questions/522466/what-makes-a-friendly-url

are the same page. I mean, I can see that the hyphenated question title gives the URL some context, but it unless you know that part's optional the URL just gets longer unnecessarily.

划一舟意中人 2024-07-20 06:20:25

首先,它们对搜索引擎爬虫很友好。 Google 和其他公司非常重视 URL 中与页面上的单词相匹配的单词,因此,如果您的博客文章的标题位于 URL 中,它将有助于您的搜索引擎获取收益。

其次,他们对那些不知道他们正在访问什么的人很友好。 如果您用于比较的哪个链接出现在您的 Twitter/电子邮件/IM/等上,您更有可能点击它?

First off, they're friendly to search engine crawlers. Google and others put a high value on words in the url that match words on the page, so if the title of your blog post is in the URL, it will help your search engine juice.

Secondly, they're friendly to people who don't know what they're visiting. Which of the links that you used for comparison are you more likely to click on if it comes across your twitter/email/IM/etc?

绝影如岚 2024-07-20 06:20:25

啊...关键在于 URL 对谁友好。 搜索引擎认为第一个网址更友好,因为它显然在网址中包含内容信息,并且看起来不像使用不同参数重复相同的页面。

例如,比较

www.aTvShowSite.com/show.aspx?id=123
www.aTvShowSite.com/show.aspx?id=124

机器人会说好吧,我不知道这些是什么......但它们对我来说看起来像是同一页面。

而比较

www.aTvShowSite.com/shows/AmericanIdol
www.aTvShowSite.com/shows/Lost

会让它们看起来像不同的页面(即使它可能是为它们提供服务的同一个 aspx 页面),并且机器人倾向于将它们排名更高。

编辑:
此外,应该指出的是,许多机器人会查看 url 的文本来确定有用性,因此搜索“Lost”可能会比第一种类型的 url 更多地命中第二种类型的 url,即使页面内容相同。

Ahh...the trick is who the URL is friendly to. Search engines perceive the first url as more friendly because it apparently has content information in the URL and it doesn't look like the same page being repeated with a different parameter.

For instance, comparing

www.aTvShowSite.com/show.aspx?id=123
www.aTvShowSite.com/show.aspx?id=124

a robot will say okay, I don't know what these are...but they look like the same page to me.

Whereas comparing

www.aTvShowSite.com/shows/AmericanIdol
www.aTvShowSite.com/shows/Lost

makes them look like different pages (even though it may be the same aspx page serving them up), and robots tend to rank them higher.

EDIT:
Additionally, it should be noted that many robots look at the text of the url to determine usefulness, so a search for "Lost" will likely hit the second type of url more than the first, even if the page content is identical.

゛清羽墨安 2024-07-20 06:20:25

至于:

这是否违反了“不要重复自己”的准则?

这指的是应用程序代码!!,而不是应用程序本身!

添加 Title 是完全有意义的

  • 中 。 标签
  • 在 URL 中
  • 并作为内容的第一行。

几乎所有其他地方的内容都需要它。

如果您的代码应该如下所示,那么“口头禅”指的是:

  <title><%=obj.getTitle()%></title>
  Reading:<h1><%=obj.getTitle()%></h1>
  Link to this:<a href="getHrefFor( object.getTitle() )">obj.getTitle()</a>
  Etc. etc.

而不是在您的应用程序周围使用复制/粘贴代码的不同方法。

As for:

Wouldn't this be a violation of the "don't repeat yourself" mantra?

That refers to the application CODE!!, not the application it self!!

It makes complete sense to have

  • Title in the <title> tag
  • In the URL
  • And as first line in the content.

And pretty much everywhere else the content need it.

What that "mantra" refers if the your code should look like this:

  <title><%=obj.getTitle()%></title>
  Reading:<h1><%=obj.getTitle()%></h1>
  Link to this:<a href="getHrefFor( object.getTitle() )">obj.getTitle()</a>
  Etc. etc.

Instead of having different methods with copy/pasted code all around your app.

请止步禁区 2024-07-20 06:20:25

您显示的“不友好”URL 暴露了实现细节:如果将来某个时候您决定放弃 ASP 并使用其他东西怎么办? 您必须更改所有 URL(糟糕!)或采用重命名方案。

在 URL 中重复标题可能不是那么必要,但当您进行大量链接粘贴时,它会很方便,可以仔细检查您是否链接到正确的位置。

The "unfriendly" URL you show exposes an implementation detail: what if, sometime in the future, you decide to drop ASP and to use something else? You would have to change all the URLs (baad!) or to employ a renaming scheme.

Having the title repeated in the URL is maybe not that necessary but it turns out handy when you do a lot of link pasting, to double check that you are linking to the correct place.

夜还是长夜 2024-07-20 06:20:25

我们的网站使用所谓的“不友好”URL,但我们会为特定位置创建特殊的“友好”URL,供公众用于特定功能,尤其是在印刷材料上。

例如,我们的停车票上有 http://www.dnv.org/parking

CP

Our website uses so-called 'unfriendly' URLs, but we create special 'friendly' URLs for specific locations that members of the public use for specific functions, especially on printed material.

For example, our parking tickets have http://www.dnv.org/parking on them.

CP

多像笑话 2024-07-20 06:20:25

好吧,首先,尝试将 (az,AZ,0-9) 和 :/._- 以外的字符排除在 url 之外。
并不是每个人的键盘上都有所有这些(例如,我的键盘上没有 &,我也没有〜)

例如,当进行一些 url 解析或类似的操作时,如果 url 语法是“干净的”

Well, for a start, try to keep characters apart from (a-z,A-Z,0-9) and of course :/._- out of the url.
Not everyone has all of those on their keyboards (for example, I don't have & on my keyboard, neither do I have ~)

When for example, doing some url parsing or something alike, also helps if the url syntax is "clean"

﹎☆浅夏丿初晴 2024-07-20 06:20:25

第二个 URL 看起来对用户更友好,而第一个 URL 看起来对搜索引擎更友好。

搜索引擎对 URL 中出现的单词给予更高的相关性。 域名获得最高优先级(因为它无法更改),URL 的其余部分获得高优先级,因为长度有限,然后分析文档正文。

我的答案是相当主观的,因为这取决于您是否对人类友好(易于手动输入,或阅读给朋友)或您是否对搜索引擎友好(提高您的排名)。

The 2nd URL looks more user friendly, whereas the first looks search-engine friendly.

Search engines give a higher relevance to words that appear in the URL. The domain name gets the highest (because it can't change), the rest of the URL gets a high priority because the length is limited, and then the body of the document is analysed.

My answer is quite subjective, because it depends on whether you are being human friendly (easy to type manually, or read to a friend) or whether you are being search engine friendly (boosting your ranking.)

唯憾梦倾城 2024-07-20 06:20:25

在这种情况下,它并没有真正违反 DRY 原则,因为就搜索引擎而言,“522466”与“what-makes-a-Friendly-url”不是一回事。

一般​​对于像 StackOverflow 这样的网站,令牌是唯一重要的信息; 通常你可以在该点之后放置任何你想要的东西,它会把你带到同一个地方(被网络服务器忽略)。

页面描述只是为了帮助搜索引擎识别页面的内容(这很好)

In this situation, it doesn't really break the DRY principal, because as far as a search engine is concerned, '522466' is not the same thing as 'what-makes-a-friendly-url'

Generally for sites like StackOverflow, the token is the only piece of information that matters; usually you can put whatever you want after that point and it'll take you to the same place (ignored by the web server).

The page description is only there to help the search engines identify what the page is about (which is nice)

月寒剑心 2024-07-20 06:20:25

另一点:人们有时会手动编辑 URL,以便进入目录树。 因此,他们可能会尝试加载类似 http://site.com/a/b 的页面,获取出现“未找到”错误,然后尝试 http://site.com/ahttp://site.com。 当然,如果您的 URL 不是基于实际的目录树,则这可能不起作用。 但您仍然可以尝试支持它。

有些浏览器甚至鼓励这样做,例如带有错误消息的 IE,以及带有右键单击页面标题时出现的菜单的 Safari。

Another point: people sometimes manually edit URLs, in order to go up the directory tree. So they might try to load a page like http://site.com/a/b, get a "Not found" error, and then try http://site.com/a or http://site.com. Of course, if your URLs aren't based on an actual directory tree, this may not work. But you can still try to support it.

Some browsers even encourage this, like IE with its error messages, and Safari with a menu that appears when you right-click the page title.

記柔刀 2024-07-20 06:20:25

Matt 和 @bigmattyh:SEO 不是“黑客”:它是理解网络上“好内容”的含义。 页面标题是内容的一部分。 链接中好的锚文本是“好的内容”(而不是使用“单击此处”等词语作为链接文本)。 将链接放在上下文中而不是作为列表才是“好内容”。

页面标题是容易实现的目标,但它们仍然是改进 SERP 的最简单方法之一。 是的,入站链接(及其质量​​)至关重要,但标题可以创造奇迹,尤其是在短期内。 您不必使用页面标题(可能会不时更改)作为帖子标题:手动总结内容。

不要猜测这些东西:(a) 阅读 SEOmoz.org 等来源,(b) 严格分析您自己的网站。

Matt and @bigmattyh: SEO is not "hacks": it's understanding what "good content" means on the web. Page titles are part of the content. Good anchor text in links is "good content" (rather than using words like "click here" as the link text). Placing links in context rather than as a list is "good content".

Page titles are low-hanging fruit, but they remain one of the easiest ways to improve SERP. Yes, inbound links (and their quality) are critical, but titles can do wonders, particularly in the short-term. You don't have to use the page title (which may change from time to time) as the post title: summarize the content manually.

Don't guess on this stuff: (a) read sources like SEOmoz.org and (b) analyze your own site rigorously.

夕色琉璃 2024-07-20 06:20:25

主题链接的内页在逻辑上相互配合。 这是隔离 URL 结构的最佳方法。

最好的例子,在不使用客户端网站的情况下,可以查看 BBC 网站,这已在最佳实践中完成:

www.bbc.com/

www.bbc.com/news

www.bbc.com/news/world

www.bbc.com/news/world/australia

内页已正确组织。 这是告诉搜索引擎如何在网站上移动的最佳实践。

Thematically linked inner pages that logically work within each other. That is the best way to Silo a URL structure.

The best example, without using client websites would be to look at the BBC website, this has been done in best practice:

www.bbc.com/

www.bbc.com/news

www.bbc.com/news/world

www.bbc.com/news/world/australia

Inner pages have been correctly organised. This is best practice to tell the search engines how to move around the website.

初见你 2024-07-20 06:20:25

术语可读网址也被经常使用。 使用友好/可读的 URL 是一种 SEO 技术,仅此而已。 否则路径越短越好。 重写规则通常会减慢将页面快速发送给客户端的过程,因此也要考虑到这一点。

The term readable url is also used a lot. Using friendly/readable urls is a SEO born technique and that is about it. Otherwise the shorter the path the better. Doing rewrite rules usually slows the process of getting the page fast to the client so take that in consideration as well.

一枫情书 2024-07-20 06:20:25

在我看来,ID 和 UUID 永远不应该成为 URL 的一部分,永远不应该。

1)一些NoSQL数据库根本不使用ID,它们使用UUID。 UUID 很长,各个部分使用破折号分隔。 Google 会将破折号视为单词分隔符:这意味着您的网址将多出 5 个无用的关键字。

2) 人类无法理解 ID 或 UUID。 一个人能够理解单词和会说话的 URL。

3)如果标题发生变化,您只需像 WordPress 那样进行重定向,就像 @TRiG 指出的那样。

4) 最后,记住使用日期,这样您就可以区分标题相同但发布于不同年、月或日的两篇文章。 例如,您可以对同一本书有两个评论(第一版和第二版)。

http://example.com/2013/02/11/data-mining-concepts-and-techniques

5

http://example.com/2011/05/23/data-mining-concepts-and-techniques

) 日期还可以帮助用户判断内容是否是最新的。

6) 日期将为您的 URL 添加一个重要的关键字:年份。 假设我想看看世界上最美丽的女孩,我会在谷歌中输入:“2014年世界上最美丽的女孩”。 我的网址将是:

http://example.com/2014/07/10/the-most-beatiful-girls-in-the-world

7) 最后但并非最不重要的一点是,Chrome 会缓存您访问过的网站,因此您只需在地址栏中输入“girls”即可找到上述网站。

In my opinion, IDs and UUIDs should never be part of the URL, never.

1) Some NoSQL databases don't use IDs at all, they use UUIDs. UUIDs are long, portions are separated using dashes. Google will treat a dash like a words separator: that means your url will have 5 more useless keywords.

2) A human being does not understand IDs or UUIDs. A person understands words and talking URLs.

3) If the title changes you can simply make a redirect like WordPress does, like @TRiG pointed.

4) Finally, remember to use a date, so you can discern between two articles having the same title and posted in a different year, month or day. For example you can have two reviews (first edition and second edition) of the same book.

http://example.com/2013/02/11/data-mining-concepts-and-techniques

and

http://example.com/2011/05/23/data-mining-concepts-and-techniques

5) A date will also help any user to figure out if the content is recent or is not.

6) A date will add an important keyword to your URL: the year. Let's suppose I want see the most beautiful girls in the world, I will type in Google: "most beautiful girls in the world 2014". My url will be:

http://example.com/2014/07/10/the-most-beatiful-girls-in-the-world

7) Last but not least, Chrome caches the site you visited, so you can find the above site just typing in the address bar "girls".

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