What is a safe maximum length a segment in a URL path should be?

The URL length shouldn't exceed 2K (just common practice). The segment path can be any size.

The domain length shouldn't be more than 255 characters (see RFC3986). Limits exist only for implementation. Segments attached to URLs are limited only in particular cases (the old common use).

Nowadays almost all requests go through one file for the rewrite rule, so segment length does not matter. After that, the segment is kept in a variable that can be very large, so there's basically no limit.


Possibly related of What is the maximum length of a URL in different browsers?

In short

According to the HTTP spec, there is no limit to a URL's length. Keep your URLs under 2048 characters; this will ensure the URLs work in all clients & server configurations. Also, search engines like URLs to remain under approximately 2000 characters.

Chrome has a 2MB limit for URLs, IE8 and 9 have a 2084 character limit. So everything points in keeping your URLs limited to approx. 2000 characters.

Also, from a usability point-of-view, URLs that long are not usable/readable by users.

However, the domain name has a max. length of 255 characters. So to be on the safe side, the max. length of an URL segment would be around 1745 characters, given that your URL exists out of 1 segment.


There is no such specification limit. There may be implementation limits, but you won't find those in the specifications.

Nit: URIs are defined by the IETF, not the W3C, and the current spec is RFC 3986.

Tags:

Http

Url

Uri