URL 格式:'&' 是否可以包含在 '?' 之前在 URL?

URL formatting: can '&' be included before '?' in the URL?

https://www.example.com/&audience=testingting?internal-abhishek-jwt=random_string

这是有效的URL吗?即首先使用 &audience 并且将 ?internal-abhishek-jwt 作为第二个查询参数是否合适?

请注意 audience& 作为前缀

Is this a valid URL?

URL spec 表示路径应该按照这些规则表示:

  path          = path-abempty    ; begins with "/" or is empty
                / path-absolute   ; begins with "/" but not "//"
                / path-noscheme   ; begins with a non-colon segment
                / path-rootless   ; begins with a segment
                / path-empty      ; zero characters

  path-abempty  = *( "/" segment )
  path-absolute = "/" [ segment-nz *( "/" segment ) ]
  path-noscheme = segment-nz-nc *( "/" segment )
  path-rootless = segment-nz *( "/" segment )
  path-empty    = 0<pchar>
  segment       = *pchar
  segment-nz    = 1*pchar
  segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
                ; non-zero-length segment without any colon ":"

  pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"

长话短说,允许在段的最后一行定义的字符类型(这是您要放置 & 的地方)。

如果我们看 sub-delims:

 sub-delims  = "!" / "$" / "&" / "'" / "(" / ")"
             / "*" / "+" / "," / ";" / "="

... 所以 & 是允许的。


也就是说,在查询字符串之外的 URL 中看到 & 是非常不寻常的

如果你把一个放在那里,那么转录 URL 的人很可能会认为你犯了一个错误并改变它......从而打破它。

所以最好避免使用它们。


i.e is it fine to have &audience first and ?internal-abhishek-jwt as the second query paramter?

没有

?开始查询字符串。将它们按此顺序排列会使 &audience 成为 路径 .

的一部分