简体   繁体   English

可以用什么字符代替 / 来分隔 URL 路径?

[英]What character can be used instead of / to separate URL path?

In a URL, according to this syntax , I want to use a different delimiter for separating path in a URL.在 URL 中,根据此语法,我想使用不同的分隔符来分隔 URL 中的路径。

For example:例如:

In this URL https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Generic_syntax , I want to separate wiki/Uniform_Resource_Identifier with a symbol other than / , but I want to make sure it does not break the URL syntax formalized by IETF . In this URL https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Generic_syntax , I want to separate wiki/Uniform_Resource_Identifier with a symbol other than / , but I want to make sure it does not break the URL syntax formalized by IETF .

I am only concerned about the path, how do I separate its components like wiki and Uniform_Resource_Identifier我只关心路径,如何分离它的组件,如wikiUniform_Resource_Identifier

You could use the URL encoding for / %2F您可以将 URL 编码用于 / %2F

https://en.wikipedia.org/wiki%2FUniform_Resource_Identifier#Generic_syntax

As far as your application's use of URIs is concerned, the / is barely more special than any other character, with two weak exceptions:就您的应用程序对 URI 的使用而言, /几乎没有比任何其他字符更特别,除了两个弱例外:

  • Using any character defined as delimiter ( gen-delims and sub-delims in RFC3986 ) has, when used as your separator, the upside that you can optionally escape it.使用任何定义为分隔符的字符( RFC3986 中的 gen-delims 和 sub-delims )在用作分隔符时,您可以选择将其转义。 That means you can have a / in your name even if you separate your components by a slash, as in wiki/AC%2FDC (which has a component AC/DC after your application does the splitting), but just the same you can separate your components with a ;这意味着即使您用wiki/AC%2FDC AC/DC组件,您的名字中也可以有/您的组件带有; and still have wiki;Steins%3bGate for Steins;Gate .并且仍然有wiki;Steins%3bGate for Steins;Gate
  • Only when using relative references, then / are special in that you can do ../../ on slashes but not with any other delimiter.仅当使用相对引用时, /的特殊之处在于您可以在斜杠上执行../../但不能使用任何其他分隔符。 (And this is the only place where the path segments really matter). (这是路径段真正重要的唯一地方)。

So really, pick whichever you like for your application;所以真的,选择你喜欢的应用程序; the client should (at least under HATEOAS, or really general REST, assumptions) not put too much meaning to the components anyway.客户应该(至少在 HATEOAS 下,或真正一般的 REST,假设)无论如何都不要对组件赋予太多意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM