大网数据广告活动
服务器运维问答

Load time impact of htaccess

· 52CE 我爱测

There are in general two possibilities of handling stuff on Apache: make configurations for folders one by one using htaccess file to fully resign htaccess and put all the rules into the httpd.conf Usage of htaccess is a load tim…

问题原文

原帖链接 · Evgeniy · CC BY-SA 3.0

There are in general two possibilities of handling stuff on Apache:

  • make configurations for folders one by one using htaccess file

  • to fully resign htaccess and put all the rules into the httpd.conf

Usage of htaccess is a load time issue. I want to know, how expensive in terms of load time is htaccess usage? Are there any tests?

社区高分解答

原帖链接 · HBruijn · CC BY-SA 3.0

The recommendation from the Apache project is:

In general, you should only use .htaccess files when you don't have access to the main server configuration file. ... a common misconception is that user authentication and mod_rewrite directives must go in .htaccess files.

So please both set AllowOverride None and all your other directives in the main httpd.conf (and/or the subsections you Include)


When Apache is not configured with AllowOverride None you already occur a (minor) performance penalty, regardless of wether or not any .htaccess files are used.

This because for each and every request apache will need to check for the presence of a potential .htaccess file in every (sub-) directory leading down to the requested resource. For example when a file is requested out of a directory /www/htdocs/example, apache must look for the following files:

/.htaccess
/www/.htaccess
/www/htdocs/.htaccess
/www/htdocs/example/.htaccess

And so, for each file access out of that directory, there are 4 additional file-system accesses, even if none of those files are present. (If AllowOveride is set for /)

The system call used for that (man 2 stat) by itself isn't that expensive and typically the file-system cache is used rather than polling the actual disk, limiting the actual IO requirements, but still it can add up, as this article argues.


When one or more actual .htaccess files are actually present, apache still needs to open and read it (triggering another IO read operation and usually also an IO write operation to update the filesystem atime attribute) and parse it before the logic therein can be applied.

Unlike when your directives are in the main httpd.conf, which only needs apache to parse them once, at startup, each .htaccess file needs to be interpreted again for each and every request.

How expensive, in addition to the IO operations, parsing the .htaccess files is depends on their complexity.

That will take careful benchmarking to determine.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-06-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。