问题
My DocumentRoot is e:/www
- below my httpd.conf
file part:
DocumentRoot "e:/www"
<Directory "e:/www">
Options FollowSymLinks
Options +Indexes
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from ::1
Allow from localhost
</Directory>
and I have 2 .htaccess
files phisically located here:
- e:/www/.htaccess
- e:/.htaccess
There is no additional Alias created in httpd.conf
file.
e:/.htaccess
is read and its contents affect server perfomance.
Why are the contents read at all??
回答1:
A couple of things to note. You should not use .htaccess if you have access to the main config file e.g. httpd.conf. It slows down your web server because Apache has to scan the directories for htaccess files and apply the rules. It is the preferred method to put it in the config in the Directory
directive. Any time the config is modified, Apache must be reloaded/restarted also.
So because it has to scan all directories it will see the .htaccess file at the level up above which in your case is e:\.htaccess
.
So if you request a file from e:\www\example. It will look for the .htaccess files in these directories
e:\.htaccess
e:\www\.htaccess
e:\www\example\.htaccess
That's why htaccess is not good for performance. It's mostly used for shared hosting or for times when you don't have direct access to the httpd.conf
file.
Read this section on When not to use .htaccess files from the Apache foundation. It will clear up any questions about this.
来源:https://stackoverflow.com/questions/24476370/apache-htaccess-file-is-read-from-the-top-drive-directory