Maximum URL Length

Normally, such pieces of information as the maximum length of a URL are completely useless. The developers of HTTP server and client software take good care of such details, so that they do not interfere with the user’s browsing experience. Yesterday, while trying to create a CGI version of a script, I realized that the URL, which was produced by a GET HTTP request, was too lengthy, so I did some research about what is the maximum amount of characters a URL can contain.

It turned out that only Internet Explorer (up to version 7.0) has a limit. According to a document on Microsoft’s help and support site, IE may accept a URL of 2083 characters max. Moreover, the path (that is may have a length of 2048 characters. As far as other browsers are concerned (Firefox, Safari, Opera), they practically have no limits in the URL length. Web servers, however, do have such limits, but this is normal for a server.

The HTTP Protocol specification does not specify a maximum URL or path length, so the implementation of such limits is left to the developers of HTTP software.

The limits described above do not apply to POST HTTP requests. The data of such requests is completely contained into their body and not in the headers, therefore it is very unlikely that the Host header or the path exceed even Internet Explorer’s limits. Note that, if you do not use a HTML form or a high-level API to generate the POST request, it is required that you set the Content-Type header to be application/x-www-form-urlencoded. You can check HTTP headers using curl.

Below, you will find the headers and the body of an example POST request:

POST /cgi-bin/test.cgi HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 41


In Python, you can generate such a urlencoded body in the following way:

>>> param = { 'firstname':'John', 'lastname':'Smith', 'phone':'12345' }
>>> import urllib
>>> print urllib.urlencode(param)

This is exactly the same as generating the data of a GET request, but without any restrictions regarding the length, which is explicitly stated in the Content-Length header. Of course, you can use any programming language you like. This was just an example.

Maximum URL Length by George Notaras is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Copyright © 2008 - Some Rights Reserved

George Notaras avatar

About George Notaras

George Notaras is the editor of the G-Loaded Journal, a technical blog about Free and Open-Source Software. George, among other things, is an enthusiast self-taught GNU/Linux system administrator. He has created this web site to share the IT knowledge and experience he has gained over the years with other people. George primarily uses CentOS and Fedora. He has also developed some open-source software projects in his spare time.

2 responses on “Maximum URL Length

  1. enfer Permalink →

    a script are present on to break down the maximum url length and it is compatible with all browser version

    you can also send an unlimited serialized string length

    this script is integrated in the JAds joomla component (ads manager component) and work fine

    for more info contact me :

    MODERATED: dauphinsky -at- hotmail [dot] com

  2. markmurphy Permalink →

    Good to know George!

    Currently building a refined search module in php for a client and was a bit concerned about the amount of characters availalbe using the $_GET in the url.

    I read somewhere (must have been a typo) that this was 256 characters.

    No need to worry now, 2000+ is plenty.