一般情况下,不应该使用.htaccess文件,除非你对Linux主服务器配置文件没有存取权限。
实际情况下,很多时候我们在不知情的条件下开启了.htaccess文件的支持,降低了apache的性能,下面让我们用strace命令跟踪一下看看:
首先:ps aux | grep httpd 查找一个httpd的进程号,比如说是123456
然后:strace -p 123456 我们就能看到类似下面的信息:
read(9, "GET /cms/media/image/bg/bg_sub_t"..., 8000) = 296
gettimeofday({1169694592, 44522}, NULL) = 0
stat64("/data/website/public/cms/media/image/bg/bg_sub_title_1.gif", {st_mode=S_IFREG|0777, st_size=176, ...}) = 0
open("/.htaccess", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
open("/data/.htaccess", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
open("/data/website/.htaccess", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
open("/data/website/public/.htaccess", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
open("/data/website/public/.htaccess", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
open("/data/website/public/cms/.htaccess", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
open("/data/website/public/cms/media/.htaccess", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
open("/data/website/public/cms/media/image/.htaccess", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
open("/data/website/public/cms/media/image/bg/.htaccess", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
open("/data/website/public/cms/media/image/bg/bg_sub_title_1.gif/.htaccess", O_RDONLY|O_LARGEFILE) = -1 ENOTDIR (Not a directory)
open("/data/website/public/cms/media/image/bg/bg_sub_title_1.gif", O_RDONLY|O_LARGEFILE) = 10
具体含义不用管,重要的是我们能够从上面的信息看出,不管我们访问什么文件,系统都在所有父级目录里不停的寻找是否有.htaccess文件,而多数情况下,我们都不会使用.htaccess文件,这样无疑白白消耗了很多资源。
那么如何禁止使用.htaccess文件呢?答案是在httpd.conf文件中设置:AllowOverride None