Apache: .htaccess file is read from the top drive directory

橙三吉。 提交于 2019-12-11 17:40:01

问题


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:

  1. e:/www/.htaccess
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!