URL片段(#)允许的字符 [英] URL fragment (#) allowed characters
问题描述
在互联网上进行了一些挖掘之后,我找不到一个很好的答案,我可以将哪些字符用作URL片段.我正在写一个JavaScript脚本,该脚本将利用URL片段.
After some digging on the internet I was unable to find a good answer to which characters I may use for URL fragment. I'm writing a javascript-script that will take advantage of URL fragments.
我想通过使URL看起来不太复杂来使其看起来更加友好.因此,我想知道是否可以使用':,?,&等字符.或者 !'在网址片段中仍然有效.
I wanted to make the URL eye-friendly by not having it looking too complicated. So I was wondering if I could use characters like ':, ?, & or !' in the URL fragment and still have it valid.
我的URL片段应包含以下值:
My URL fragment should contain the following values:
- 订购者
- id
- desc 或 asc
- order-by
- id
- desc or asc
- /the/full/escaped/path/here/
推荐答案
tl; dr
片段标识符组件可以包含:
tl;dr
The fragment identifier component can contain:
-
0
-9
-
a
-z
-
A
-Z
-
?
/
:
@
-
.
_
~
!
$
&
'
(
)
*
,
;
=
- 百分号字符(
%
后跟两个十六进制数字)
0
-9
a
-z
A
-Z
?
/
:
@
-
.
_
~
!
$
&
'
(
)
*
+
,
;
=
- percent-encoded characters (a
%
followed by two hexadecimal digits)
URI标准为 STD 66 ,该标准当前映射到
The URI standard is STD 66, which currently maps to RFC 3986.
在本文档中,您将找到所有需要了解的内容.
In this document, you’ll find everything you need to know.
在第3.5节中定义了 片段标识符组件 :
The fragment identifier component is defined in section 3.5:
fragment = *( pchar / "/" / "?" )
这意味着该片段可以不包含任何内容或(的任何组合)
This means that the fragment can contain nothing or (any combination of)
-
pchar
中定义的 - 个字符
-
/
-
?
- characters defined in pchar
- the
/
- the
?
请参阅附录A.以了解 pchar 已定义:
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
所以这增加了
-
在未保留
中定义的 - 个字符
- 以 pct编码 定义的字符 在 sub-delims 中定义的
- 个字符
-
:
-
@
- characters defined in unreserved
- characters defined in pct-encoded
- characters defined in sub-delims
- the
:
- the
@
现在检查如何定义未保留:
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
这会添加
-
ALPHA 中定义的
- 个字符 DIGIT 中定义的
- 个字符
-
-
-
.
-
_
-
~
- characters defined in ALPHA
- characters defined in DIGIT
- the
-
- the
.
- the
_
- the
~
检查如何定义ALPHA和DIGIT.它们未在附录中列出,因为它们来自核心ABNF规则,就像第1.3节中所述:
Check how ALPHA and DIGIT are defined. They are not listed in the appendix, because they are from the core ABNF rules, as is explained in section 1.3:
ALPHA(字母),[…] DIGIT(十进制数字)[…]
ALPHA (letters), […] DIGIT (decimal digits) […]
所以这增加了
-
a
-z
,A
-Z
-
0
-9
a
-z
,A
-Z
0
-9
检查如何定义 pct编码:
pct-encoded = "%" HEXDIG HEXDIG
这允许使用任何百分比编码的字符.
检查 sub-delims 的定义方式:
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
这会添加
-
!
-
$
-
&
-
'
-
(
-
)
-
*
-
+
-
,
-
;
-
=
- the
!
- the
$
- the
&
- the
'
- the
(
- the
)
- the
*
- the
+
- the
,
- the
;
- the
=
这篇关于URL片段(#)允许的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!