采用拼音 URL

发布时间: 2017-05-11 14:03:18 作者: 大象笔记

为什么要采用拼音 URL

如何定义 URL 的格式

可以学习 stackoverflow 的做法:

http://stackoverflow.com/questions/1101957/are-there-any-standard-exit-status-codes-in-linux

学习 stackoverflow 的做法,实际上 id 已经能够代表这篇文章,但是 stackoverflow 301 跳转到了新地址,即带描述的地址。

$ curl -v http://stackoverflow.com/questions/1101957                                                                                                                                       
* Hostname was NOT found in DNS cache
* *   Trying 198.252.206.140...
* * Connected to stackoverflow.com (198.252.206.140) port 80 (#0)
* > GET /questions/1101957 HTTP/1.1
* > User-Agent: curl/7.35.0
* > Host: stackoverflow.com
* > Accept: */*
* > 
* < HTTP/1.1 301 Moved Permanently
* < Cache-Control: public, no-cache="Set-Cookie", max-age=60
* < Content-Type: text/html; charset=utf-8
* < Expires: Tue, 20 May 2014 06:14:35 GMT
* < Last-Modified: Tue, 20 May 2014 06:13:35 GMT
* < Location:
/questions/1101957/are-there-any-standard-exit-status-codes-in-linux
< Vary: *
< X-Frame-Options: SAMEORIGIN
< Set-Cookie: prov=4bab85c7-f446-463a-97e9-a6b834ad29ab;
domain=.stackoverflow.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/;
HttpOnly
< Date: Tue, 20 May 2014 06:13:35 GMT
< Content-Length: 185
< 
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a
href="/questions/1101957/are-there-any-standard-exit-status-codes-in-linux">here</a>.</h2>
</body></html>
* Connection #0 to host stackoverflow.com left intact

代码实现

可以使用 pypinyin 这个库结合 jieba 分词,将中文转换为拼音。

需要注意的地方:

我是一名山东烟台的开发者,联系作者