24

I have a long URL with several values.

Example 1:

http://www.domain.com/list?seach_type[]=0&search_period[]=1&search_min=3000&search_max=21000&search_area=6855%3B7470%3B7700%3B7730%3B7741%3B7742%3B7752%3B7755%3B7760%3B7770%3B7800%3B7840%3B7850%3B7860%3B7870%3B7884%3B7900%3B7950%3B7960%3B7970%3B7980%3B7990%3B8620%3B8643%3B8800%3B8830%3B8831%3B8832%3B8840%3B8850%3B8860%3B8881%3B9620%3B9631%3B9632

My variable search area contains only 4 number digits (example 4000, 5000), but can contain a lot of them. Right now I seperate these in the URL by using ; as separator symbol. Though as seen in Example 1, the ; is converted into %3B. This makes me believe that this is a bad symbol to use.

What is the best URL separator?

bluish
  • 26,356
  • 27
  • 122
  • 180
Kristian
  • 1,343
  • 4
  • 29
  • 47

5 Answers5

43

Moontear, I think you have misread the linked document. That limitation only applies to the "scheme" portion of the URL. In the case of WWW URLs, that is the "http".

The next section of the document goes on to say:

Thus, only alphanumerics, the special characters "$-_.+!*'(),", and reserved characters used for their reserved purposes may be used unencoded within a URL.

I'd personally use comma (,). However, plus (+) and dash (-) are both reasonable options as well.

BTW, that document also mentions that semi-colon (;) is reserved in some schemes.

GinoA
  • 732
  • 1
  • 6
  • 11
14

Well, according to RFC1738, valid URLs may only contain the letters a-z, the plus sign (+), period and hyphen (-).

Generally I would go with a plus to separate your search areas. So your URL would become http://www.example.com/list?seach_type=0&search_period=1&search_min=3000&search_max=21000&search_area=6855+7470+7700+...

--EDIT--

As GinoA pointed out I misread the document. Hence "$-_.+!*'()," are valid characters too in an unencoded URL. I'd still go with the + sign though.

Dennis G
  • 21,405
  • 19
  • 96
  • 133
5

If there are only numbers to separate, you have a large choice of separators. You can choose any letter for example.

Probably a space can be a good choice. It will be transformed into + character in the URL, so will be more readable than a letter.

Example: search_area=4000+5000+6000

Arseni Mourzenko
  • 50,338
  • 35
  • 112
  • 199
2

I'm very late to the party, but a valid query string can repeat variables so instead of...

http://x.y.z/list?type=0&period=1&min=3000&max=21000&area=6855+7470+7700

...you could also use...

http://x.y.z/list?type=0&period=1&min=3000&max=21000&area=6855&area=7470&area=7700
dacracot
  • 22,002
  • 26
  • 104
  • 152
  • And most of the web frameworks handle this out of the box, the search area elements get parsed as a list automatically. – viam0Zah Jun 07 '21 at 13:25
1

"+" is to be interpreted as a space " " when the content-type is application/x-www-form-urlencoded (standard for HTML forms). This may be handled by your server software.

I prefer "!". It doesn't get URL encoded (at least not in Chrome) and it reserves "+" for use as a real space character in the typical case.

rich remer
  • 3,407
  • 2
  • 34
  • 47
  • 1
    Just wanted to point out (4.5 years after the fact) that Chrome (v70.0.3538.77 (Official Build) (64-bit) at least) now encodes `!` to `%21` – Kingsley Jan 02 '19 at 20:50
  • The ! after percent encoding becomes %21. I think the question did not include any client specific mechanism but encoding that maybe needs to be done in the delimiters. – Sakis Oct 08 '20 at 10:49