What makes a “friendly URL”?

2019-01-10 01:34发布

I've read a great deal of discussion recently (both on this site and elsewhere) about "friendly URLs" but I'm not sure what exactly makes a URL "friendly" and why we really even care (up to a certain point). Illustration:

The following is an example of a URL that would be held up by the majority of current web developers as "friendly":

www.myblog.com/posts/123/this-is-the-name-of-my-blog-post

Whereas this would be considered "unfriendly" (i.e. bad, Neanderthal, ignorant, stupid):

www.myblog.com/posts.aspx?id=123

My questions:

  • Doesn't the "friendly" URL contain duplicate identifying information about the blog post in question? In other words, once you have the id (123) of the post, why do you need the title? Wouldn't this be a violation of the "don't repeat yourself" mantra?
  • What difference does the form of a URL make as far as users are concerned? Do users ever actually type full URLs by hand (other than the TLD, of course)? Do users ever look to the URL of a page to determine what the page is about? Why do we need the title of the blog post in the URL? Isn't that what the page's <title> tag and content are for?
  • I often hear SEO as a reason why the "friendly" URL form is preferred. Why does a search engine spider care about the URL? Aren't they just automated pieces of software that crawl pages (and the links to other pages that are contained within them)? If search engines were written like other software components (e.g. database access components), the URL would just be a meaningless identifier (similar to a rowguid in a relational database) to them. If I were designing a database schema with something like the "friendly" URL above as a table's primary key, I would (quite correctly) get chewed out.

I said earlier "up to a point" because obviously, URLs can get out of hand. Here is an actual URL from Amazon.com that I don't think anyone in their right mind would consider "friendly":

http://www.amazon.com/Bissell-Kitchen-Housewares/b/ref=amb_link_5001972_17?ie=UTF8&node=694500&pf_rd_m=ATVPDKIKX0DER&pf_rd_s=gp-center-5&pf_rd_r=1ZXNJFE0CCFFDH4B9HGH&pf_rd_t=101&pf_rd_p=405478901&pf_rd_i=510080

19条回答
等我变得足够好
2楼-- · 2019-01-10 02:21

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.
查看更多
放我归山
3楼-- · 2019-01-10 02:22

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.

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-01-10 02:23

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.

查看更多
Viruses.
5楼-- · 2019-01-10 02:27

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

查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-01-10 02:28

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.

查看更多
小情绪 Triste *
7楼-- · 2019-01-10 02:32

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.

查看更多
登录 后发表回答