Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What characters can one use in a URL?

Tags:

url

rfc

I have an application that takes all the parameters in the url like this: /category/subcategory/sub-subcategory. I want to be able to give out extra parameters at the end of the URL, like page-2/order-desc. This would make the whole URL into cat/subcat/sub-subcat{delimiting-character}page-2/order-desc.

My question is: what characters could I use as {delimiting-character}. I tend to prefer ":" as I know for sure it will never appear anyplace else but I don't know if it would be standard compliant or at least if it will not give me problems in the future.

As I recall vimeo used something like this: vimeo.com/video:{code} but they seem to have changed this.

like image 991
Sorin Buturugeanu Avatar asked Apr 13 '11 13:04

Sorin Buturugeanu


People also ask

What characters are invalid in a URL?

These characters are "{", "}", "|", "\", "^", "~", "[", "]", and "`". All unsafe characters must always be encoded within a URL.

What punctuation is allowed in a URL?

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

Can you put symbols in a URL?

It is common for websites to use alphanumeric character and only one special character, the hyphen, to separate words. It is unlikely that anyone would expect to see or type a special character other than the hyphen into a URL.


2 Answers

You can use alphanumeric, plus the special characters "$-_.+!*'()," More info here: http://www.ietf.org/rfc/rfc1738.txt

Also, take note not to exceed 2000 characters in url

like image 108
andrew Avatar answered Oct 11 '22 14:10

andrew


The most recent URI spec is RFC 3986; see the ABNF for details on what characters are allowed in which parts for the URI.

The format for an absolute path part is:

  path-absolute = "/" [ segment-nz *( "/" segment ) ]
  segment       = *pchar
  segment-nz    = 1*pchar
  pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"
  pct-encoded   = "%" HEXDIG HEXDIG
  unreserved    = ALPHA / DIGIT / "-" / "." / "_" / "~"
  sub-delims    = "!" / "$" / "&" / "'" / "(" / ")"
                      / "*" / "+" / "," / ";" / "="
like image 26
McDowell Avatar answered Oct 11 '22 14:10

McDowell