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

124 Views Asked by At

In a URL, according to this syntax, I want to use a different delimiter for separating path in a 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.

I am only concerned about the path, how do I separate its components like wiki and Uniform_Resource_Identifier

2

There are 2 best solutions below

0
On

As far as your application's use of URIs is concerned, the / is barely more special than any other character, with two weak exceptions:

  • 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. 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 ; and still have 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.

2
On

You could use the URL encoding for / %2F

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