Are slashes allowed in URL fragment or query?

后端 未结 3 853
忘了有多久
忘了有多久 2021-01-06 13:58

My understanding of the general form of a URL is that it looks as follows:

://?#


        
相关标签:
3条回答
  • 2021-01-06 14:11

    STD 66 defines the fragment as:

    fragment = *( pchar / "/" / "?" )

    So aside from characters from the pchar set (unreserved / pct-encoded / sub-delims / ":" / "@"), the / and the ? can be used in the fragment directly (i.e., percent-encoding is not needed).

    The / is even mentioned explicitly in the text:

    The characters slash ("/") and question mark ("?") are allowed to represent data within the fragment identifier. Beware that some older, erroneous implementations may not handle this data correctly when it is used as the base URI for relative references (Section 5.1).

    0 讨论(0)
  • 2021-01-06 14:23

    Fragment can contain any character at all.

    Query can contain any character except for #, as it is treated as marker (but you can use URL-encoding to still have it there)

    So, in general, there are no any reserved characters as long as there is no ambiguity.

    See RFC 3987 for the most up-to-date info. Your "general form" is not exactly right

    0 讨论(0)
  • 2021-01-06 14:29

    of course you can use / in both fragment and query

    An example:

    <a href='#vol/p'>hash example</a>
    
    <div style='min-height:500px;'></div>
    <div id='vol/p'>
        <a href='http://jsfiddle.net/echo/jsonp?weep/sho/sdf=help'>get example</a>
    </div>
    

    jsfiddle demo

    Basically you can use anything that can be encoded in an URL. moreinfo

    0 讨论(0)
提交回复
热议问题