Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

http

url

uri

A lot of people are asking "What is the maximum length a URL can be?" but as far as I can see nobody is asking the question:

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

I think this question is equally as important.

This question is a general question aimed at supporting as many systems out of the box as possible.

In C#, you can get a list of URL path segments from an incoming request, with security modules installed what is considered the maximum length a segment in a URL path can be for this scenario?

I've read on the following page that URL path segments over 260 characters can cause problems in custom ASP.NET modules:

  • http://www.paraesthesia.com/archive/2011/08/26/long-url-path-segments-in-asp-net-routing-yield-400.aspx/

In web browsers, you type URL segments regardless of what website you visit, / is a URL path segment which is usually mapped to a homepage. With Internet Explorer, Chrome and Firefox being popular browsers, what is the maximum length of a URL path segment length they support?

I can see from the following resource that the maximum length of a URL path differs for different browsers and the figure is sometimes quite high:

  • What is apache's maximum url length?

But this is a path and not a path segment.

I'm also aware that when rewriting paths, the underlying file system path length comes into play, and the ball park figure of what I can see supported is around 255 characters in a *nix OS.

Other considerations include the maximum length of a URL path segment in a database table. For instance, in MySQL a varchar column can contain up to 255 characters, but is there a case for this, are people storing segments of paths in tables in MySQL or are people storing full URL's in varchar columns? Could this mean 255 characters is too long for a URL path segment?

Is there any W3C specification on how long a URL path segment can be as I can't spot anything?

I did read the W3C specification on URI's but again I didn't spot anything of use:

  • http://www.ietf.org/rfc/rfc2396.txt

I'm quite baffled that there is no set standard on what a length a URL path segment should be, so maybe I am missing something?

I'm really looking for as much information as possible on what different systems support, and what is considered a safe length for a URL path segment.

like image 466
Professor of programming Avatar asked Apr 05 '15 14:04

Professor of programming


People also ask

What is the maximum length of a URL?

The official documentation specifies a maximum length of 2048 characters for the <loc> element, which is used to submit URLs: URL of the page. This URL must begin with the protocol (e.g. “http”) and end with a trailing slash if required by the web server. This value must not exceed 2,048 characters.

What should be the URL length?

Recommendation. A URL should not exceed 2000 characters, so that it can be parsed with a Browser. However, URLs of this length are rare. If you want a URL to appear in the search results complete and not truncated, it should be a maximum of 74 characters.

What is the maximum length of a URL in Chrome?

Chrome limits URLs to a maximum length of 2MB for practical reasons and to avoid causing denial-of-service problems in inter-process communication. On most platforms, Chrome's omnibox limits URL display to 32kB ( kMaxURLDisplayChars ) although a 1kB limit is used on VR platforms.

What is the maximum length of query string in URL?

Although officially there is no limit specified by RFC 2616, many security protocols and recommendations state that maxQueryStrings on a server should be set to a maximum character limit of 1024. While the entire URL, including the querystring, should be set to a max of 2048 characters.


2 Answers

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.

like image 170
Gerrit Bertier Avatar answered Sep 29 '22 07:09

Gerrit Bertier


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.

like image 20
Julian Reschke Avatar answered Sep 29 '22 07:09

Julian Reschke