Is a URL allowed to contain a space?

后端 未结 10 1279
慢半拍i
慢半拍i 2020-11-22 04:02

Is a URI (specifically an HTTP URL) allowed to contain one or more space characters? If a URL must be encoded, is + just a commonly followed convention

相关标签:
10条回答
  • 2020-11-22 04:25

    Can someone point to an RFC indicating that a URL with a space must be encoded?

    URIs, and thus URLs, are defined in RFC 3986.

    If you look at the grammar defined over there you will eventually note that a space character never can be part of a syntactically legal URL, thus the term "URL with a space" is a contradiction in itself.

    0 讨论(0)
  • 2020-11-22 04:28

    Shorter answer: no, you must encode a space; it is correct to encode a space as +, but only in the query string; in the path you must use %20.

    0 讨论(0)
  • 2020-11-22 04:30

    Yes, the space is usually encoded to "%20" though. Any parameters that pass to a URL should be encoded, simply for safety reasons.

    0 讨论(0)
  • 2020-11-22 04:30

    URL can have an Space Character in them and they will be displayed as %20 in most of the browsers, but browser encoding rules change quite often and we cannot depend on how a browser will display the URL.

    So Instead you can replace the Space Character in the URL with any character that you think shall make the URL More readable and ' Pretty ' ;) ..... O so general characters that are preferred are "-","_","+" .... but these aren't the compulsions so u can use any of the character that is not supposed to be in the URL Already.

    Please avoid the %,&,},{,],[,/,>,< as the URL Space Character Replacement as they can pull up an error on certain browsers and Platforms.

    As you can see the Stak overflow itself uses the '-' character as Space(%20) replacement.

    Have an Happy questioning.

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