URI 的任何路径段都可以有查询组件吗?

发布于 11-16 14:22 字数 450 浏览 3 评论 0原文

根据 第 3.3 节,路径组件 >RFC2396 - 统一资源标识符

该路径可以由一系列由单个斜杠“/”字符分隔的路径段组成。在路径段中,字符“/”、“;”、“=”和“?”被保留。每个路径段可以包括一系列参数,由分号“;”指示。特点。这些参数对于相对引用的解析并不重要。

但是,除了最后一个片段之外,我从未在任何片段中见过带有查询参数的 URL。所以,我不确定我是否正确地阅读了这篇文章。

http://www.url.com/segment1?seg1param1=val1/page.html?pageparam1=val2 是有效的 URL 吗?

According to the Section 3.3, Path Component of RFC2396 - Uniform Resource Identifiers,

The path may consist of a sequence of path segments separated by a single slash "/" character. Within a path segment, the characters "/", ";", "=", and "?" are reserved. Each path segment may include a sequence of parameters, indicated by the semicolon ";" character. The parameters are not significant to the parsing of relative references.

However, I have never seen a URL with a query parameters in any segment other than the final one. So, I am not sure if I am reading this correctly.

Is http://www.url.com/segment1?seg1param1=val1/page.html?pageparam1=val2 a valid URL?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

奈何桥上唱咆哮2024-11-23 14:22:26

RFC 所指的内容是这样的:

http://www.example.com/foo/bar;param=value/baz.html

可以将其解释为带有参数 param=value 的路径 /foo/bar/baz.htmlbar 段。不使用问号。

请注意,RFC 2396 已被 RFC 3986 废弃,后者省略了以下规范特定于段的参数有利于一般注意,实现可以(并且确实)做不同的事情来嵌入特定于段的参数:

除了分层路径中的点段之外,路径段是
通用语法认为是不透明的。 URI 生成应用程序
经常使用段中允许的保留字符来分隔
特定于方案或特定于解引用处理程序的子组件。为了
例如,分号(“;”)和等号(“=”)保留字符是
通常用于分隔适用于的参数和参数值
那段。逗号(“,”)保留字符通常用于
类似的目的。例如,一个 URI 生产者可能会使用一个段
例如“name;v=1.1”表示对版本 1.1 的引用
“name”,而另一个可能使用诸如“name,1.1”之类的段来
表示相同。参数类型可以由特定于方案的定义
语义,但在大多数情况下,参数的语法特定于
URI 解除引用算法的实现。

What the RFC is referring to is something like this:

http://www.example.com/foo/bar;param=value/baz.html

That could be interpreted as the path /foo/bar/baz.html with the parameter param=value to the bar segment. No question marks are used.

Note that RFC 2396 has been obsoleted by RFC 3986, which omits specification of segment-specific parameters in favor of a general note that implementations can (and do) do different things to embed segment-specific parameters:

Aside from dot-segments in hierarchical paths, a path segment is
considered opaque by the generic syntax. URI producing applications
often use the reserved characters allowed in a segment to delimit
scheme-specific or dereference-handler-specific subcomponents. For
example, the semicolon (";") and equals ("=") reserved characters are
often used to delimit parameters and parameter values applicable to
that segment. The comma (",") reserved character is often used for
similar purposes. For example, one URI producer might use a segment
such as "name;v=1.1" to indicate a reference to version 1.1 of
"name", whereas another might use a segment such as "name,1.1" to
indicate the same. Parameter types may be defined by scheme-specific
semantics, but in most cases the syntax of a parameter is specific to
the implementation of the URI's dereferencing algorithm.

誰認得朕2024-11-23 14:22:26

当你看下面的语法时,它是这样写的:

 路径 = [ 绝对路径 |不透明部分]

  path_segments = 段 *( "/" 段 )
  段 = *pchar *( ";" 参数 )
  参数 = *pchar

  pchar = 未保留 |逃脱|
                  “:” | “@”| “&” | “=”| “+”| “$” | “,”

一个段由 pchar 和 param 组成,param 本身就是一个 pchar。
当我们继续读下去的时候,绝对没有“?”了。 pchar 字符组件中的字符。所以参数中不能有“?”,也不能有“?”分段。

所以我同意爱德华·汤姆森的回答,他说“?”仅分隔查询段,不能在路径内使用。

When you look at the grammar which is just below, it is written:

  path          = [ abs_path | opaque_part ]

  path_segments = segment *( "/" segment )
  segment       = *pchar *( ";" param )
  param         = *pchar

  pchar         = unreserved | escaped |
                  ":" | "@" | "&" | "=" | "+" | "$" | ","

A segment is composed of pchar and param, param being itself a pchar.
When we continue to read, there is absolutely no "?" character in the pchar character components. So the parameters cannot have any "?", and there cannot be a "?" in segments.

So I agree with the answer of Edward Thomson, who says that "?" only delimit the query segment, and cannot be used inside a path.

三生一梦2024-11-23 14:22:26

根据我对 RFC 2396 的阅读,? 是保留字符,仅用于分隔查询段。路径或查询段中不允许使用 ?

在您的示例中,第一个 ? 标记查询段的开始。第二个 ? 位于查询段内,是不允许的。

According to my reading of RFC 2396, no. The ? is a reserved character and serves only to delimit the query segment. The ? is not allowed in either the path or the query segment.

In your example, the first ? marks the beginning of the query segment. The second ? is inside the query segment, and is disallowed.

美男兮2024-11-23 14:22:26

我相信你可以用它做一个 get ,大多数网络服务器都会处理它,但我不相信你会得到你期望的结果。也就是说 pageparam1=val2 不会评估。

如果你想要这样的参数,你总是可以使用 # 符号(就像现在很多基于 javascript 的 GUI 所做的那样)。

I believe you could do a get with that and most web servers would process it but I don't believe you would get the results you are expecting. That is the pageparam1=val2 would not evaluate.

If you want parameters like that you could always use the # symbol (as a lot of javascript based GUIs do now).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文