URL 在不同浏览器中的最大长度是多少? [英] What is the maximum length of a URL in different browsers?

查看:49
本文介绍了URL 在不同浏览器中的最大长度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个网址在不同浏览器中的最大长度是多少?浏览器之间有区别吗?

What is the maximum length of a URL in different browsers? Does it differ among browsers?

最大 URL 长度是 HTTP 规范的一部分吗?

Is a maximum URL length part of the HTTP specification?

推荐答案

简短回答 - 事实上限制为 2000 个字符

如果您将 URL 保持在 2000 个字符以下,它们几乎可以在客户端和服务器软件的任何组合中使用.

Short answer - de facto limit of 2000 characters

If you keep URLs under 2000 characters, they'll work in virtually any combination of client and server software.

如果您的目标是特定浏览器,请参阅下文以了解有关特定限制的更多详细信息.

If you are targeting particular browsers, see below for more details on specific limits.

RFC 2616(超文本传输​​协议 HTTP/1.1)第 3.2.1 节说

RFC 2616 (Hypertext Transfer Protocol HTTP/1.1) section 3.2.1 says

HTTP协议没有放置对长度的任何先验限制一个 URI.服务器必须能够处理他们服务的任何资源的 URI,并且应该能够处理如果他们提供无限长度可以生成基于 GET 的表单这样的 URI.服务器应该返回414(请求 URI 太长)状态,如果URI 比服务器长句柄(见第 10.4.15 节).

The HTTP protocol does not place any a priori limit on the length of a URI. Servers MUST be able to handle the URI of any resource they serve, and SHOULD be able to handle URIs of unbounded length if they provide GET-based forms that could generate such URIs. A server SHOULD return 414 (Request-URI Too Long) status if a URI is longer than the server can handle (see section 10.4.15).

该 RFC 已被 RFC7230 废弃,这是一个刷新 HTTP/1.1 规范.它包含类似的语言,但还继续提出以下建议:

That RFC has been obsoleted by RFC7230 which is a refresh of the HTTP/1.1 specification. It contains similar language, but also goes on to suggest this:

请求行长度的各种特别限制见实践.建议所有 HTTP 发送方和接收方至少支持 8000 个八位字节的请求行长度.

Various ad hoc limitations on request-line length are found in practice. It is RECOMMENDED that all HTTP senders and recipients support, at a minimum, request-line lengths of 8000 octets.

...和现实

这就是标准所说的.对于现实,有一篇文章关于boutell.com(链接到 Internet Archive 备份)讨论了单个浏览器和服务器实现将支持的内容.执行摘要是:

...and the reality

That's what the standards say. For the reality, there was an article on boutell.com (link goes to Internet Archive backup) that discussed what individual browser and server implementations will support. The executive summary is:

极长的 URL 通常是错误.网址超过 2,000 个字符在最流行的网络中不起作用浏览器. 如果您打算,请不要使用它们您的网站适用于大多数互联网用户.

Extremely long URLs are usually a mistake. URLs over 2,000 characters will not work in the most popular web browsers. Don't use them if you intend your site to work for the majority of Internet users.

(注意:这是一篇 2006 写的文章的引述,但在 2015 年 IE 的使用量下降意味着更长的 URL 确实适用于大多数人.然而,IE仍然有限制...)

(Note: this is a quote from an article written in 2006, but in 2015 IE's declining usage means that longer URLs do work for the majority. However, IE still has the limitation...)

IE8 的最大 URL 长度为 2083 个字符,看来 IE9 也有类似的限制.

我测试了 IE10,地址栏只接受 2083 个字符.您可以点击一个比这更长的网址,但地址栏仍然只会显示该链接的 2083 个字符.

I've tested IE10 and the address bar will only accept 2083 chars. You can click a URL which is longer than this, but the address bar will still only show 2083 characters of this link.

IE Internals 博客上有一篇不错的文章 介绍了这方面的一些背景.

There's a nice writeup on the IE Internals blog which goes into some of the background to this.

有混合报告 IE11 支持更长的 URL - 请参阅下面的评论.鉴于有些人报告了问题,一般建议仍然有效.

There are mixed reports IE11 supports longer URLs - see comments below. Given some people report issues, the general advice still stands.

请注意站点地图协议,该协议允许站点将可用页面通知搜索引擎, 在 URL 中限制为 2048 个字符.如果您打算使用站点地图,已经为您确定了一个限制!(请参阅下面的Calin-Andrei Burloiu 的回答)

Be aware that the sitemaps protocol, which allows a site to inform search engines about available pages, has a limit of 2048 characters in a URL. If you intend to use sitemaps, a limit has been decided for you! (see Calin-Andrei Burloiu's answer below)

2010 年也有一些关于 最大 URL 长度搜索引擎将进行抓取和索引.他们发现限制为 2047 个字符,这似乎与站点地图协议规范有关.但是,他们还发现 Google SERP 工具无法处理超过 1855 个字符的网址.

There's also some research from 2010 into the maximum URL length that search engines will crawl and index. They found the limit was 2047 chars, which appears allied to the sitemap protocol spec. However, they also found the Google SERP tool wouldn't cope with URLs longer than 1855 chars.

CDN 也对 URI 长度施加限制,当达到这些限制时将返回 414 Too long request,例如:

CDNs also impose limits on URI length, and will return a 414 Too long request when these limits are reached, for example:

  • Fastly 8Kb
  • CloudFront 8Kb
  • CloudFlare 32Kb

(感谢 timrs2998 在评论中提供该信息)

(credit to timrs2998 for providing that info in the comments)

我针对配置了非常大的 的 Apache 2.4 服务器测试了以下内容LimitRequestLineLimitRequestFieldSize.

I tested the following against an Apache 2.4 server configured with a very large LimitRequestLine and LimitRequestFieldSize.

Browser     Address bar   document.location
                          or anchor tag
------------------------------------------
Chrome          32779           >64k
Android          8192           >64k
Firefox          >64k           >64k
Safari           >64k           >64k
IE11             2047           5120
Edge 16          2047          10240

另见这个回答来自下面的 Matas Vaitkevicius.

See also this answer from Matas Vaitkevicius below.

这是一个很受欢迎的问题,由于最初的研究已有大约 14 年的历史,我会尽量保持最新:截至 2020 年 9 月,建议仍然有效.尽管 IE11 可能接受更长的 URL,但普遍存在的旧版 IE 安装加上搜索引擎的限制意味着保持在 2000 个字符以下是最好的一般策略.

This is a popular question, and as the original research is ~14 years old I'll try to keep it up to date: As of Sep 2020, the advice still stands. Even though IE11 may possibly accept longer URLs, the ubiquity of older IE installations plus the search engine limitations mean staying under 2000 chars is the best general policy.

这篇关于URL 在不同浏览器中的最大长度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆