担心 httpd.conf 有数千个 301 重定向的潜在性能问题

Worried about potential performance issue with httpd.conf with thousands of 301 redirects

我一直在做关于永久 301 重定向的进一步研究。

我正在重新设计网站,有 4,000 个页面正在更改它们的 URL,所以我有几千个 301 重定向语句,其中 URL 变化太大,以至于我无法使用正则表达式。

我一直在研究将它们放入 .htaccess 文件或 httpd.conf 之间的性能差异。我正在阅读并获得有关每种好处的相互矛盾的信息。

即这听起来很有希望:

"Note, if you are using Apache then it's strongly recommended to put the redirect rules in your httpd.conf (stored in memory when Apache starts) and not .htaccess files (which are loaded on every page request)." 来源 - Major site rewrite and SEO with 301 redirects

但随后与此发生冲突:

"You can use Include directive in httpd.conf to be able to maintain redirects in another file. But it would not be very efficient, as every request would need to be checked against a lot of regular expressions. " 来源 - http://www.faqoverflow.com/serverfault/414225.html

我的房东说: "No performance impact with httpd.conf, you're in effect doing the same thing as adding them to the config itself. But you are doing so in a way that will not cause issues with it or have the changes lost."

向 httpd.conf 添加数千个 301 重定向语句不会导致我的站点出现性能问题是否正确?

Is it correct that adding thousands of 301 re-direct statements to httpd.conf won't cause performance issues for my site?

数千个重定向都可以。我听说或有人试图对几乎没有重大影响的东西进行基准测试,比服务器 OS 的常规东西更重要。

您的第二个引述完全错误,至少就 apache 2.2-2.4 而言是这样。当您使用 Include 指令时,它会加载文件的内容作为服务器配置的一部分。这意味着它在您启动服务器时加载,或者当您明确告诉 apache 重新加载其配置时。它不会查看每个请求的所有 Included 个文件。

Apache 相当自由地使用这个指令,因为在大多数开箱即用的配置中使用 Include 来加载每个模块配置和每个虚拟主机配置的整个目录。