apache URL 中是否允许使用冒号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1737575/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Are colons allowed in URLs?
提问by Emanuil Rusev
I thought using colons in URIs was "illegal". Then I saw that vimeo.com is using URIs like http://www.vimeo.com/tag:sample.
我认为在 URI 中使用冒号是“非法的”。然后我看到 vimeo.com 正在使用类似的 URIhttp://www.vimeo.com/tag:sample.
- What do you feel about the usage of colons in URIs?
- How do I make my Apache server work with the "colon" syntax because now it's throwing the "Access forbidden!" error when there is a colon in the first segment of the URI?
- 您对 URI 中冒号的使用有何看法?
- 我如何让我的 Apache 服务器使用“冒号”语法,因为它现在抛出“禁止访问!” URI 的第一段中有冒号时出错?
回答by Gumbo
Colons are allowed in the URI path. But you need to be careful when writing relative URI paths with a colon since it is not allowed when used like this:
URI 路径中允许使用冒号。但是在使用冒号编写相对 URI 路径时需要小心,因为这样使用时是不允许的:
<a href="tag:sample">
In this case tagwould be interpreted as the URI's scheme. Instead you need to write it like this:
在这种情况下,tag将被解释为 URI 的方案。相反,你需要这样写:
<a href="./tag:sample">
回答by SQLighter
Also note the difference between Apache on Linux and Windows. Apache on Windows somehow doesn't allow colons to be used in the first part of the URL. Linux has no problem with this, however.
还要注意Linux 和 Windows 上的 Apache 之间的区别。Windows 上的 Apache 以某种方式不允许在 URL 的第一部分使用冒号。然而,Linux 没有这个问题。
回答by rsp
Are colons allowed in URLs?
URL 中是否允许使用冒号?
Yes, unless it's in the first path segment of a relative-path reference
是的,除非它位于相对路径引用的第一个路径段中
So for example you can have a URL like this:
例如,您可以有这样的 URL:
And you can use it normally as an absolute URL or some relative variants:
您可以正常使用它作为绝对 URL 或一些相对变体:
<a href="https://en.wikipedia.org/wiki/Template:Welcome">Welcome Template</a>
<a href="/wiki/Template:Welcome">Welcome Template</a>
<a href="wiki/Template:Welcome">Welcome Template</a>
But this would be invalid:
但这将是无效的:
<a href="Template:Welcome">Welcome Template</a>
because the "Template" here would be mistaken for the protocol scheme. You would have to use:
因为这里的“模板”会被误认为是协议方案。你将不得不使用:
<a href="./Template:Welcome">Welcome Template</a>
to use a relative link from a page on the same level in the hierarchy.
使用来自层次结构中同一级别页面的相对链接。
The spec
规格
See the RFC 3986, Section 3.3:
请参阅 RFC 3986,第 3.3 节:
The path component contains data, usually organized in hierarchical form, that, along with data in the non-hierarchical query component (Section 3.4), serves to identify a resource within the scope of the URI's scheme and naming authority (if any). The path is terminated by the first question mark ("?") or number sign ("#") character, or by the end of the URI.
If a URI contains an authority component, then the path component must either be empty or begin with a slash ("/") character. If a URI does not contain an authority component, then the path cannot begin with two slash characters ("//"). In addition, a URI reference (Section 4.1) may be a relative-path reference, in which case the first path segment cannot contain a colon (":") character.The ABNF requires five separate rules to disambiguate these cases, only one of which will match the path substring within a given URI reference. We use the generic term "path component" to describe the URI substring matched by the parser to one of these rules. [emphasis added]
路径组件包含通常以分层形式组织的数据,这些数据与非分层查询组件(第 3.4 节)中的数据一起用于标识 URI 方案和命名权限(如果有)范围内的资源。路径以第一个问号 ("?") 或数字符号 ("#") 字符或 URI 的结尾终止。
如果 URI 包含权限组件,则路径组件必须为空或以斜杠 ("/") 字符开头。如果 URI 不包含权限组件,则路径不能以两个斜杠字符 (“//”) 开头。 此外,URI 引用(第 4.1 节)可能是相对路径引用,在这种情况下,第一个路径段不能包含冒号 (":") 字符。ABNF 需要五个单独的规则来消除这些情况的歧义,其中只有一个将匹配给定 URI 引用中的路径子字符串。我们使用通用术语“路径组件”来描述解析器与这些规则之一匹配的 URI 子字符串。【强调】
Example URL that uses a colon:
使用冒号的示例 URL:

