片段标识符在 URL 中的有效字符列表?

我使用片段标识符为我的 web 应用程序 和这个人很像中的 AJAX 事件创建一个永久链接,比如:

http://www.myapp.com/calendar#filter:year/2010/month/5

我已经做了相当多的搜索,但找不到片段标识符的有效字符列表。W3C 规范不提供任何服务。

我是否需要编码的字符相同的网址在一般?

好像没什么有用的信息。

19140 次浏览

See the RFC 3986.

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

So you can use !, $, &, ', (, ), *, +, ,, ;, $0, something matching $1, something matching $2, $3, $4, $5, $6, $7, $8, $9, and &0

https://www.rfc-editor.org/rfc/rfc3986#section-3.5:

fragment    = *( pchar / "/" / "?" )

and

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

So, combined, the fragment %1 contain #, a raw %, ^, [, ], {, }, \, ", < and %0 according to the RFC.

One other RFC speak of that: RFC-1738

URL schemeparts for ip based protocols:
HTTP


httpurl        = "http://" hostport [ "/" hpath [ "?" search ]]
hpath          = hsegment *[ "/" hsegment ]
hsegment       = *[ uchar | ";" | ":" | "@" | "&" | "=" ]
search         = *[ uchar | ";" | ":" | "@" | "&" | "=" ]