URL,URN,URI的区别

参考:

https://danielmiessler.com/study/url-uri/

https://www.cnblogs.com/wuyun-blog/p/5706703.html

https://blog.csdn.net/u010525694/article/details/78591355

 

1.URI (Uniform Resource Identifier) 统一资源标识符,标识抽象的或者物理资源。URI可以进一步分为URL,URN或同时具备locators 和names特性的一个东西。URN作用就好像一个人的名字,URL就像一个人的地址。换句话说:URN确定了东西的身份,URL提供了找到它的方式。

举个栗子:

  • 首先,URL是URI的一种。
  • 让URI能成为URL的当然就是那个“访问机制”,“网络位置”。e.g. http:// or ftp://.。
  • URN是唯一标识的一部分,就是一个特殊的名字。

  下面就来看看例子吧,当来也是来自权威的RFC:

  • ftp://ftp.is.co.za/rfc/rfc1808.txt (also a URL because of the protocol)
  • http://www.ietf.org/rfc/rfc2396.txt (also a URL because of the protocol)
  • ldap://[2001:db8::7]/c=GB?objectClass?one (also a URL because of the protocol)
  • mailto:John.Doe@example.com (also a URL because of the protocol)
  • news:comp.infosystems.www.servers.unix (also a URL because of the protocol)
  • tel:+1-816-555-1212
  • telnet://192.0.2.16:80/ (also a URL because of the protocol)
  • urn:oasis:names:specification:docbook:dtd:xml:4.1.2

  这些全都是URI, 其中有些事URL. 哪些? 就是那些提供了访问机制的.

2.HttpServletRequest 的API 

http://127.0.0.1:8080/icbc-visa/apply/test

request.getContextPath() : /icbc-visa
request.getRequestURI() : /icbc-visa/apply/test
request.getRequestURL() : http://127.0.0.1:8080/icbc-visa/apply/test
request.getPathInfo() : /apply/test
request.getServletPath() :  PS:This method will return an empty string ("") if the servlet used to process this request was matched using the "/*" pattern.
request.getServletContext().getRealPath() : E:\workspace\icbc-visa-build\icbc-visa-project\icbc-visa-portals\icbc-visa-website\src\main\webapp
request.getScheme() : http
request.getServerName() : 127.0.0.1
request.getServerPort() : 8080

3.URL 末尾 带/和不带/的区别

http://www.abc.com/abc
http://www.abc.com/abc/
       对于用户来说,在大多数情况下这两个网址没有任何区别,他们访问的都是网站abc目录下的默认首页。一般用户也都知道最后一个斜杠是可有可无的,他们输入网址的时候一般都只会输入http://www.abc.com/abc。

  当Web服务器接收到对某个末尾不含斜杠的url请求时,例如“http://www.abc.com/abc”,这时服务器会搜索网站根目录下有没有名为“abc”的文件,如果没有就把abc当做目录处理,然后返回abc目录下的默认首页。当Web服务器接收到的是末尾带斜杠的请求时就会直接当做目录处理。

  这是在微软IEBlog里看到的一篇文章:

  When generating hyperlinks, always include a trailing slash if possible. For instance, navigating to http://msdn.microsoft.com/ie takes one more roundtrip than http://msdn.microsoft.com/ie/. When the browser navigates to the /ie url, the server merely sends down a 301 to the /ie/ url. Both links work, but the second version is faster.

  简单来说就是,当浏览器解析 /ie 这样的url时,服务器会执行301转向到/ie/,两个链接都有效,但是第二种更快。当然这个转向的时间一般是感觉不到的,几乎可以忽略。

  对于搜索引擎,这两个地址是有可能同时收录的,上次在某SEO高手博客上看到,说某一关键词的搜索结果中,一个站点带“/”与不带“/”的网址同时出现在了搜索结果的首页,应该是百度的一个BUG,不知道现在还有没有。

  wikipedia上链接都是采用不带“/”的形式,例如 http://en.wikipedia.org/wiki/Search_engine_optimization,你可以去看wikipedia相关页面的收录情况,收录的也都是不带“/”的网址。

  可能很多朋友看到这就不明白了,那到底用哪种形式呢?

  我的观点和大多数SEO高手的观点一致,就是在目录形式的url结尾都带上“/”,特别是交换链接的时候,链接都用http://www.xxxx.com/ 这种形式,一定要注意哦。

  对于那些已经采用了不带“/”网址的站长,也没关系,你可以像wikipedia一样继续采用这种形式的url,但是要注意链接的统一性,不要有的地方用带“/”的,有的地方用不带“/”的

  如果你不想保留这种链接,可以直接将链接全部做301转向到带“/”的,以后在网站中就全部用带“/”的url吧。

 

posted on 2019-09-04 17:40  scottyu  阅读(252)  评论(0)    收藏  举报

导航