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条回答
你好瞎i
2楼-- · 2019-01-10 02:08

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?

查看更多
走好不送
3楼-- · 2019-01-10 02:10

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.

查看更多
We Are One
4楼-- · 2019-01-10 02:10

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.

查看更多
Rolldiameter
5楼-- · 2019-01-10 02:11

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"

查看更多
smile是对你的礼貌
6楼-- · 2019-01-10 02:11

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.

查看更多
做自己的国王
7楼-- · 2019-01-10 02:12

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.

查看更多
登录 后发表回答