URL的目录部分的有效字符(用于短链接) [英] Valid Characters for Directory part of a URL (for short links)
问题描述
除了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.
是否有一个定义的标准可以在浏览器供应商尊重的网址中使用哪些字符?
Is there a defined Standard on what characters can be used in a url that browser vendors respect?
推荐答案
路径段(路径中的部分由绝对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 = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
所以它基本上是 A
- Z
, a
- z
, 0
- 9
, -
,。
, _
,〜
,!
, $
,&
,'
,(
,)
, *
, +
,,
,;
, =
,:
, @
,以及%
必须后跟两个十六进制数字。任何其他字符/字节都需要使用百分比编码进行编码。
So it’s basically A
–Z
, a
–z
, 0
–9
, -
, .
, _
, ~
, !
, $
, &
, '
, (
, )
, *
, +
, ,
, ;
, =
, :
, @
, 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个字母数字字符(即 A
- Z
, a
- z
, 0
- 9
)或使用URL和文件名安全字母表进行Base 64编码(即 A
- Z
, a
- z
, 0
- 9
, -
, _
)。
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. A
–Z
, a
–z
, 0
–9
) or the Base 64 Encoding with URL and Filename Safe Alphabet (i.e. A
–Z
, a
–z
, 0
–9
, -
, _
).
这篇关于URL的目录部分的有效字符(用于短链接)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!