How to Increase Max URL Length in Apache Server

Apache is a popular web server used by many websites and blogs. It supports a vast range of URLs, including complex ones found on ecommerce sites. But sometimes it may give you an error ‘414 – Request Too Long’. In such cases, you may need to increase the max URL length permitted by Apache server. In this article, we will learn how to change max URL length supported by Apache server.

Error 414 Request Too Long

Sometimes Apache server can return error response ‘414 Request Too Long‘. You get this error when the requested URL is too long, much longer than the max URL length supported by Apache server. Such error is generally encountered in GET requests, where the entire request query data is included in request URL. To fix this problem, you should either shorten requested URL or increase max URL length. Alternatively, you may also change the request type to POST so that all query data is sent as POST data, and not appended to request path as query string.

What is Default Max URL Length in Apache

By default, Apache supports a URL of max 8190 bytes. From this, you can subtract 3 bytes for request type (e.g. GET), and another 8 bytes for version information (e.g. HTTP/1.0 or HTTP/1.1) and 2 bytes for separating space, then you are left with 8177 bytes for URI path and query.

Why Increase URL Length

Although the default max URL length in Apache works for most websites, here are some legitimate use cases, where you may need to actually increase its limit

  1. Complex applications – There may be certain applications that commonly depend on GET requests for filtering and reporting data. They may use search queries, filtering parameters in GET request URL itself. This will result in large URLs.
  2. API requirements – Certain APIs may result in long URLs due to vast number of parameters supported for filtering, searching, sorting and other types of querying.
  3. Legacy Systems – Some old systems may use longer URLs that need to be truncated while migrating to newer systems.
  4. Request too large – Sometimes users may get the error 414 Request Too Large, mentioned above. In such cases also, you need to increase max URL limit in Apache.

How to Increase Max URL Length in Apache

Here are the steps to increase max url length in Apache server. We need to add or modify the LimitRequestLine Directive which controls the max url length in Apache server.

1. Open Apache Configuration

First, we need to open Apache configuration file in text editor.

Ubuntu/Debian

vi /etc/apache2/apache2.conf

Redhat/Fedora/CentOS

vi /etc/httpd/conf/httpd.conf

2. Add or Modify LimitRequestLine

Next, add or modify LimitRequestLine server directive. Here is its syntax.

LimitRequestLine no_of_bytes

Its default value is 8190 bytes. Change it as per your requirement.

LimitRequestLine 16000

If you also face problems with certain request headers being too long, then you can also add or modify LimitRequestFieldSize directive, which controls size of individual request headers.

LimitRequestFieldSize no_of_bytes

Save and quit configuration file.

3. Restart Apache Server

Restart Apache server to apply changes.

Ubuntu/Debian

sudo service apache2 restart

Redhat/Fedora/CentOS

sudo systemctl restart httpd

Conclusion

In this article, we have learnt how to increase max URL length in Apache. If your website users are frequently getting ‘414 Request Too Long’ error message then you may want to increase the max URL supported by your web server. On the other hand, you should also investigate your site’s URL format and see if it can be shortened. You may need to re-design your URL format in some cases. Alternatively, you may also check if you can send request query data as POST instead of GET request type. The default max url size is sufficient for most websites and blogs. It is only in extraordinary cases that you generally need to increase it. If you need to change it, then you can follow the steps mentioned above.

Also read:
How to Enable mod_ssl in Apache Server
How to Enable CORS in Apache Server
How to Increase Max Connections in Apache

Leave a Reply

Your email address will not be published. Required fields are marked *