Connected: An Internet Encyclopedia
RFC 1808 - 2.2. BNF for Relative URLs

Top: Connected: An Internet Encyclopedia
Up: Requests For Comments
Up: RFC 1808
Up: 2. Relative URL Syntax
Prev: 2.1. URL Syntactic Components
Next: 2.3. Specific Schemes and their Syntactic Categories

### 2.2. BNF for Relative URLs

This is a BNF-like description of the Relative Uniform Resource Locator syntax, using the conventions of RFC 822 [5], except that "|" is used to designate alternatives. Briefly, literals are quoted with "", parentheses "(" and ")" are used to group elements, optional elements are enclosed in [brackets], and elements may be preceded with <n>* to designate n or more repetitions of the following element; n defaults to 0.

This BNF also describes the generic-RL syntax for valid base URLs. Note that this differs from the URL syntax defined in RFC 1738 [2] in that all schemes are required to use a single set of reserved characters and use them consistently within the major URL components.

       URL         = ( absoluteURL | relativeURL ) [ "#" fragment ]

       absoluteURL = generic-RL | ( scheme ":" *( uchar | reserved ) )

       generic-RL  = scheme ":" relativeURL

       relativeURL = net_path | abs_path | rel_path

       net_path    = "//" net_loc [ abs_path ]
       abs_path    = "/"  rel_path
       rel_path    = [ path ] [ ";" params ] [ "?" query ]

       path        = fsegment *( "/" segment )
       fsegment    = 1*pchar
       segment     =  *pchar

       params      = param *( ";" param )
       param       = *( pchar | "/" )

       scheme      = 1*( alpha | digit | "+" | "-" | "." )
       net_loc     =  *( pchar | ";" | "?" )
       query       =  *( uchar | reserved )
       fragment    =  *( uchar | reserved )

       pchar       = uchar | ":" | "@" | "&" | "="
       uchar       = unreserved | escape
       unreserved  = alpha | digit | safe | extra

       escape      = "%" hex hex
       hex         = digit | "A" | "B" | "C" | "D" | "E" | "F" |
                             "a" | "b" | "c" | "d" | "e" | "f"

       alpha       = lowalpha | hialpha
       lowalpha    = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" |
                     "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" |
                     "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
       hialpha     = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" |
                     "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" |
                     "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"

       digit       = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |
                     "8" | "9"

       safe        = "$" | "-" | "_" | "." | "+"
       extra       = "!" | "*" | "'" | "(" | ")" | ","
       national    = "{" | "}" | "|" | "\" | "^" | "~" | "[" | "]" | "`"
       reserved    = ";" | "/" | "?" | ":" | "@" | "&" | "="
       punctuation = "<" | ">" | "#" | "%" | <">

Next: 2.3. Specific Schemes and their Syntactic Categories

Connected: An Internet Encyclopedia
RFC 1808 - 2.2. BNF for Relative URLs