URL 目录部分的有效字符(对于短链接) [英] Valid characters for directory part of a URL (for short links)

查看:27
本文介绍了URL 目录部分的有效字符(对于短链接)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了 A-Za-z0-9 之外,还有其他字符可以用来缩短链接而不会遇到麻烦吗?:)

Are there any other characters except A-Za-z0-9 that can be used to shorten links without getting into trouble? :)

我在考虑 +、;- 或其他东西.

I was thinking about +,;- or something.

对于浏览器供应商尊重的 URL 中可以使用哪些字符,是否有明确的标准?

Is there a defined standard regarding what characters can be used in a URL that browser vendors respect?

推荐答案

A 绝对URI路径中的路径段(路径中由/分隔的部分)可以包含零个或多个pchar,其定义如下:

A path segment (the parts in a path separated by /) in an absolute URI path can contain zero or more of pchar that is defined as follows:

  pchar       = unreserved / pct-encoded / sub-delims / ":" / "@"
  pct-encoded = "%" HEXDIG HEXDIG
  unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"
  sub-delims  = "!" / "$" / "&" / "'" / "(" / ")"
              / "*" / "+" / "," / ";" / "="

所以基本上是AZ, az, 09, -, ., _, ~, !, $, &, ', (, ), *, +, , , ;, =, :@ 以及 % 后必须跟两个十六进制数字.任何其他字符/字节都需要使用 percent-encoding 进行编码.

So it’s basically AZ, az, 09, -, ., _, ~, !, $, &, ', (, ), *, +, ,, ;, =, :, @, as well as % that must be followed by two hexadecimal digits. Any other character/byte needs to be encoded using the percent-encoding.

尽管总共有 79 个字符可以在路径段中逐字使用,但一些用户代理也会对其中的一些字符进行编码(例如 %7E 而不是 ~代码>).这就是为什么许多人只使用 62 个字母数字字符(即 AZaz09) 或 Base64 使用 URL 和文件名安全字母编码(即 AZ, az,09, -, _).

Although these are 79 characters in total that can be used in a path segment literally, some user agents do encode some of these characters as well (e.g. %7E instead of ~). That’s why many use just the 62 alphanumeric characters (i.e. AZ, az, 09) or the Base 64 Encoding with URL and Filename Safe Alphabet (i.e. AZ, az, 09, -, _).

这篇关于URL 目录部分的有效字符(对于短链接)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆