面部提升做什么项目最好| 法器是什么意思| 吃什么壮阳补肾| 常乐我净是什么意思| 白带有点黄是什么原因| 左小腹疼是什么原因| 老是睡不着觉是什么原因| 香油是什么油| anello是什么牌子| 什么叫阳性率| 刑事拘留意味着什么| 苹果是什么季节的水果| 喉咙扁桃体发炎吃什么药| 花名是什么意思| 什么的搏斗| 产后拉肚子是什么原因引起的| 大拇指指甲凹凸不平是什么原因| 睡眠不好会引起什么症状| 乌龟不吃食是什么原因| 拉肚子吃什么抗生素| 看脑血管挂什么科| 2月28号是什么星座| 极性什么意思| arrior是什么牌子轮胎| 血压高吃什么| 拔牙挂什么科室| 一片冰心在玉壶是什么意思| 什么东西泡脚减肥| 荼什么意思| 8月15日是什么星座| 甲泼尼龙主要治什么| 一模一样的意思是什么| 人彘是什么| 效果是什么意思| 云南小黄姜和普通姜有什么区别| 三什么一什么四字词语| gtp什么意思| 10月11日是什么星座| 为什么镜子不能对着床| 佛手柑是什么| 六月六吃什么| 男性左下腹疼痛是什么原因| 钙不能和什么一起吃| 心有戚戚焉什么意思| 补办港澳通行证需要什么材料| 1984年是什么年| 什么是比值| 眼睛看东西模糊是什么原因| 什么屎不臭答案| 尿多是什么原因引起的| 草莓印是什么| 喜用神是什么| 月经吃什么水果好| 原始心管搏动是什么意思| 三点水山今读什么| 不知不觉是什么意思| 心肌酶是查什么的| 吃什么增肥最快| 二甲双胍缓释片什么时候吃最好| ly是什么意思| 风加具念什么| 什么给我带来快乐| 五险一金是指什么| 鹿晗和邓超什么关系| 落马是什么意思| 手指麻木是什么原因| 十一月是什么月| 小肠与什么相表里| 念字五行属什么| 阴茎破皮擦什么药| 常喝苦荞茶有什么好处| 3月2日是什么星座| 维生素b6治什么病| 小孩体质差吃什么能增强抵抗力| 什么的风| 7号来的月经什么时候是排卵期| 项羽的马叫什么名字| 幽门螺杆菌是什么病| 人体七大营养素是什么| 为伊消得人憔悴什么意思| 胸口闷挂什么科| 吃什么下奶快| 香菜吃多了有什么坏处| 手和脚发麻是什么原因| 为什么男生| 技师是干什么的| 查甲状腺功能挂什么科| 是什么歌曲| 意会是什么意思| plt医学上是什么意思| 差是什么意思| 走马观花的走什么意思| 甲功四项是什么检查项目| 流鼻涕感冒吃什么药| 牛奶盒属于什么垃圾| 在什么什么前面| 农历3月是什么月| 羊肠小道什么意思| 汕头市花是什么花| 医生为什么看瞳孔知道没救了| 血小板高有什么危害| 严重贫血的人吃什么补血最快| 第一次是什么意思| 仓鼠可以吃什么水果| 吃芒果对身体有什么好处| 花朵像什么| 血氨高会导致什么后果| 今年7岁属什么生肖| 小孩鼻子出血什么原因| 咸池是什么意思| ecl是什么意思| 小本生意做什么好赚钱快| 脚怕冷是什么原因引起的| 点痣后需要注意什么事项| 梦见手表是什么意思| 秋葵什么时候播种| 铜钱癣用什么药| 阳瘘的最佳治疗方法是什么| 女性为什么会得疱疹| 总是爱出汗是什么原因| 8月26日是什么星座| 蚊子怕什么气味| 一清二白是什么意思| 肉桂跟桂皮有什么区别| 禁锢是什么意思| 林深时见鹿什么意思| 密度灶是什么意思| hg是什么意思| 抓拍是什么意思| 一月14号是什么星座| 去侍庙有什么禁忌| 什么是一二三级医院| 子宫内膜不典型增生是什么意思| 马驹是什么意思| 牙膏什么牌子最好| 低回声是什么意思| 小兔子吃什么| 人体最大的排毒器官是什么| 与世无争是什么意思| 肝火大吃什么药| 囊中羞涩什么意思| 谷丙转氨酶偏高是什么原因| 芽轴发育成什么| 气血不足补什么| 蚜虫长什么样| 溪字五行属什么| 送什么小礼品好| 木瓜是什么味道| 小猫吃什么| 什么人不能喝丹参| 孕妇应该吃什么蔬菜| 头发有点黄是什么原因| 疣是一种什么病| 端午节什么时候吃粽子| 中午12点到1点是什么时辰| 执念是什么意思| 秋葵吃多了有什么坏处| 保险费率是什么| 1.14是什么星座| 汐字五行属什么| 舒张压偏低是什么原因| 穆斯林不吃什么| 为什么磨牙| 熬夜头疼是什么原因| 孕妇喝什么水好| 瞿读什么| 吃什么排铅最快| 打磨工是做什么的| 脾虚湿盛吃什么药| 泪囊炎用什么眼药水| 双子女和什么星座最配| 1.8是什么星座| 青春永驻什么意思| 优雅从容的意思是什么| 虎牙长什么样子| 更年期出虚汗吃什么药| 燃气是什么气体| 螳螂捕蝉黄雀在后是什么意思| 轻微手足口病吃什么药| 蝶窦炎是什么病| 喉咙发炎吃什么水果好| 手脱皮是缺什么| 爆肝是什么意思| 支气管炎什么症状| 阿耨多罗三藐三菩提是什么意思| 县武装部长是什么级别| 红蜘蛛用什么药最有效| 一只眼睛充血是什么原因| 2月14日是什么星座| a1微球蛋白偏高说明什么意思| 梦见蛇吃人代表什么预兆| 脚酸是什么原因引起的| 依达拉奉注射功效与作用是什么| 备孕检查什么项目| 什么烟最便宜| 胃火重口臭吃什么药好| 吃什么补脑子增强记忆力最快| 猕猴桃不能和什么一起吃| meshor是什么牌子的手表| 猫癣长什么样| 什么地站着| 原子序数是什么| 杨梅有什么功效| 血栓的症状是什么| 梦见苍蝇很多是什么意思| 肾脏不好吃什么食物好| 临汾有什么大学| 玉米淀粉可以做什么| 新生儿黄疸高有什么危害| 回盲瓣呈唇形什么意思| 女中指戴戒指什么意思| 落汤鸡是什么意思| cpb是什么牌子| 青柠是什么水果| 脂肪肝能吃什么水果| 梦见小婴儿是什么意思| 薄荷有什么功效和作用| 什么什么的田野| 生蚝是什么东西| 声线是什么意思| 什么而不舍| 鹿吃什么| rose是什么意思| 疤痕子宫什么意思| 89年什么命| 维生素c什么时候吃| 食物中毒吃什么药| 云南古代叫什么| 虫可念什么| 什么是疣体| 什么样的你| 胆的作用和功能是什么| charleskeith什么牌子| 什么是融合菜| 什么是强直性脊柱炎| 淋巴细胞低是什么原因| 诊断是什么意思| hcv阳性是什么意思| 经常掉头发是什么原因| 同房痛什么原因引起的| 狗属于什么类动物| 牙痛是什么原因引起的| 失眠是什么原因| 别出心裁的裁是什么意思| 头七需要做什么| 佐匹克隆是什么药| 蛊是什么意思| 无锡机场叫什么名字| 吃什么指甲长得快| 什么是点天灯| 什么是双向抑郁| 皮肤松弛是什么原因造成的| 山药有什么功效| 心脏不好挂什么科| 海藻糖是什么糖| 7月22日什么星座| 氯读什么拼音| 秤砣是什么意思| 手信是什么意思| 生化全项包括什么| 黑脸代表什么| 女人打掉孩子说明什么| 李白有什么诗| 大陆去台湾需要什么手续| 百度
<-
Apache > HTTP Server > Documentation > Version 2.4 > How-To / Tutorials

竞彩明星业主候选人系列报道:山西运城张相平

百度 四要做好个人预防。

Available Languages:  en  |  es  |  fr  |  ja  |  ko  |  pt-br 

.htaccess files provide a way to make configuration changes on a per-directory basis.

Support Apache!

See also

top

.htaccess files

You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance.
top

What they are/How to use them

.htaccess files (or "distributed configuration files") provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.

Note:

If you want to call your .htaccess file something else, you can change the name of the file using the AccessFileName directive. For example, if you would rather call the file .config then you can put the following in your server configuration file:

AccessFileName ".config"

In general, .htaccess files use the same syntax as the main configuration files. What you can put in these files is determined by the AllowOverride directive. This directive specifies, in categories, what directives will be honored if they are found in a .htaccess file. If a directive is permitted in a .htaccess file, the documentation for that directive will contain an Override section, specifying what value must be in AllowOverride in order for that directive to be permitted.

For example, if you look at the documentation for the AddDefaultCharset directive, you will find that it is permitted in .htaccess files. (See the Context line in the directive summary.) The Override line reads FileInfo. Thus, you must have at least AllowOverride FileInfo in order for this directive to be honored in .htaccess files.

Example:

Context: server config, virtual host, directory, .htaccess
Override: FileInfo

If you are unsure whether a particular directive is permitted in a .htaccess file, look at the documentation for that directive, and check the Context line for ".htaccess".

top

When (not) to use .htaccess files

In general, you should only use .htaccess files when you don't have access to the main server configuration file. There is, for example, a common misconception that user authentication should always be done in .htaccess files, and, in more recent years, another misconception that mod_rewrite directives must go in .htaccess files. This is simply not the case. You can put user authentication configurations in the main server configuration, and this is, in fact, the preferred way to do things. Likewise, mod_rewrite directives work better, in many respects, in the main server configuration.

.htaccess files should be used in a case where the content providers need to make configuration changes to the server on a per-directory basis, but do not have root access on the server system. In the event that the server administrator is not willing to make frequent configuration changes, it might be desirable to permit individual users to make these changes in .htaccess files for themselves. This is particularly true, for example, in cases where ISPs are hosting multiple user sites on a single machine, and want their users to be able to alter their configuration.

However, in general, use of .htaccess files should be avoided when possible. Any configuration that you would consider putting in a .htaccess file, can just as effectively be made in a <Directory> section in your main server configuration file.

There are two main reasons to avoid the use of .htaccess files.

The first of these is performance. When AllowOverride is set to allow the use of .htaccess files, httpd will look in every directory for .htaccess files. Thus, permitting .htaccess files causes a performance hit, whether or not you actually even use them! Also, the .htaccess file is loaded every time a document is requested.

Further note that httpd must look for .htaccess files in all higher-level directories, in order to have a full complement of directives that it must apply. (See section on how directives are applied.) Thus, if a file is requested out of a directory /www/htdocs/example, httpd 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. (Note that this would only be the case if .htaccess files were enabled for /, which is not usually the case.)

In the case of RewriteRule directives, in .htaccess context these regular expressions must be re-compiled with every request to the directory, whereas in main server configuration context they are compiled once and cached. Additionally, the rules themselves are more complicated, as one must work around the restrictions that come with per-directory context and mod_rewrite. Consult the Rewrite Guide for more detail on this subject.

The second consideration is one of security. You are permitting users to modify server configuration, which may result in changes over which you have no control. Carefully consider whether you want to give your users this privilege. Note also that giving users less privileges than they need will lead to additional technical support requests. Make sure you clearly tell your users what level of privileges you have given them. Specifying exactly what you have set AllowOverride to, and pointing them to the relevant documentation, will save yourself a lot of confusion later.

Note that it is completely equivalent to put a .htaccess file in a directory /www/htdocs/example containing a directive, and to put that same directive in a Directory section <Directory "/www/htdocs/example"> in your main server configuration:

.htaccess file in /www/htdocs/example:

Contents of .htaccess file in /www/htdocs/example

AddType text/example ".exm"

Section from your httpd.conf file

<Directory "/www/htdocs/example">
    AddType text/example ".exm"
</Directory>

However, putting this configuration in your server configuration file will result in less of a performance hit, as the configuration is loaded once when httpd starts, rather than every time a file is requested.

The use of .htaccess files can be disabled completely by setting the AllowOverride directive to none:

AllowOverride None
top

How directives are applied

The configuration directives found in a .htaccess file are applied to the directory in which the .htaccess file is found, and to all subdirectories thereof. However, it is important to also remember that there may have been .htaccess files in directories higher up. Directives are applied in the order that they are found. Therefore, a .htaccess file in a particular directory may override directives found in .htaccess files found higher up in the directory tree. And those, in turn, may have overridden directives found yet higher up, or in the main server configuration file itself.

Example:

In the directory /www/htdocs/example1 we have a .htaccess file containing the following:

Options +ExecCGI

(Note: you must have "AllowOverride Options" in effect to permit the use of the "Options" directive in .htaccess files.)

In the directory /www/htdocs/example1/example2 we have a .htaccess file containing:

Options Includes

Because of this second .htaccess file, in the directory /www/htdocs/example1/example2, CGI execution is not permitted, as only Options Includes is in effect, which completely overrides any earlier setting that may have been in place.

Merging of .htaccess with the main configuration files

As discussed in the documentation on Configuration Sections, .htaccess files can override the <Directory> sections for the corresponding directory, but will be overridden by other types of configuration sections from the main configuration files. This fact can be used to enforce certain configurations, even in the presence of a liberal AllowOverride setting. For example, to prevent script execution while allowing anything else to be set in .htaccess you can use:

<Directory "/www/htdocs">
    AllowOverride All
</Directory>

<Location "/">
    Options +IncludesNoExec -ExecCGI
</Location>
This example assumes that your DocumentRoot is /www/htdocs.
top

Authentication example

If you jumped directly to this part of the document to find out how to do authentication, it is important to note one thing. There is a common misconception that you are required to use .htaccess files in order to implement password authentication. This is not the case. Putting authentication directives in a <Directory> section, in your main server configuration file, is the preferred way to implement this, and .htaccess files should be used only if you don't have access to the main server configuration file. See above for a discussion of when you should and should not use .htaccess files.

Having said that, if you still think you need to use a .htaccess file, you may find that a configuration such as what follows may work for you.

.htaccess file contents:

AuthType Basic
AuthName "Password Required"
AuthUserFile "/www/passwords/password.file"
AuthGroupFile "/www/passwords/group.file"
Require group admins

Note that AllowOverride AuthConfig must be in effect for these directives to have any effect.

Please see the authentication tutorial for a more complete discussion of authentication and authorization.

top

Server Side Includes example

Another common use of .htaccess files is to enable Server Side Includes for a particular directory. This may be done with the following configuration directives, placed in a .htaccess file in the desired directory:

Options +Includes
AddType text/html shtml
AddHandler server-parsed shtml

Note that AllowOverride Options and AllowOverride FileInfo must both be in effect for these directives to have any effect.

Please see the SSI tutorial for a more complete discussion of server-side includes.

top

Rewrite Rules in .htaccess files

When using RewriteRule in .htaccess files, be aware that the per-directory context changes things a bit. In particular, rules are taken to be relative to the current directory, rather than being the original requested URI. Consider the following examples:

# In httpd.conf
RewriteRule "^/images/(.+)\.jpg" "/images/$1.png"

# In .htaccess in root dir
RewriteRule "^images/(.+)\.jpg" "images/$1.png"

# In .htaccess in images/
RewriteRule "^(.+)\.jpg" "$1.png"

In a .htaccess in your document directory, the leading slash is removed from the value supplied to RewriteRule, and in the images subdirectory, /images/ is removed from it. Thus, your regular expression needs to omit that portion as well.

Consult the mod_rewrite documentation for further details on using mod_rewrite.

top

CGI example

Finally, you may wish to use a .htaccess file to permit the execution of CGI programs in a particular directory. This may be implemented with the following configuration:

Options +ExecCGI
AddHandler cgi-script cgi pl

Alternately, if you wish to have all files in the given directory be considered to be CGI programs, this may be done with the following configuration:

Options +ExecCGI
SetHandler cgi-script

Note that AllowOverride Options and AllowOverride FileInfo must both be in effect for these directives to have any effect.

Please see the CGI tutorial for a more complete discussion of CGI programming and configuration.

top

Troubleshooting

When you put configuration directives in a .htaccess file, and you don't get the desired effect, there are a number of things that may be going wrong.

Most commonly, the problem is that AllowOverride is not set such that your configuration directives are being honored. Make sure that you don't have a AllowOverride None in effect for the file scope in question. A good test for this is to put garbage in your .htaccess file and reload the page. If a server error is not generated, then you almost certainly have AllowOverride None in effect.

If, on the other hand, you are getting server errors when trying to access documents, check your httpd error log. It will likely tell you that the directive used in your .htaccess file is not permitted.

[Fri Sep 17 18:43:16 2010] [alert] [client 192.168.200.51] /var/www/html/.htaccess: DirectoryIndex not allowed here

This will indicate either that you've used a directive that is never permitted in .htaccess files, or that you simply don't have AllowOverride set to a level sufficient for the directive you've used. Consult the documentation for that particular directive to determine which is the case.

Alternately, it may tell you that you had a syntax error in your usage of the directive itself.

[Sat Aug 09 16:22:34 2008] [alert] [client 192.168.200.51] /var/www/html/.htaccess: RewriteCond: bad flag delimiters

In this case, the error message should be specific to the particular syntax error that you have committed.

Available Languages:  en  |  es  |  fr  |  ja  |  ko  |  pt-br 

top

Comments

Notice:
This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Libera.chat, or sent to our mailing lists.
背靠背是什么意思 打鼾是什么原因引起的 养老金什么时候补发 八面玲珑代表什么生肖 幽冥是什么意思
叶绿素是什么 翡翠a货是什么意思 肛门坠胀吃什么药最好 海蜇长什么样 什么都不做
胃肠感冒什么症状 为什么我不快乐 莳花弄草是什么意思 高山仰止是什么意思 孕妇吃什么长胎不长肉
六味地黄丸有什么副作用 表面抗原阳性是什么意思 腰椎钙化是什么意思 陋习什么意思 眩晕症吃什么药
云南白药植物长什么样jasonfriends.com 白露是什么季节的节气hcv7jop6ns5r.cn 空气缸是什么意思hcv8jop3ns0r.cn 肾炎康复片主要是治疗什么hcv8jop7ns7r.cn 61年属什么生肖hcv8jop3ns8r.cn
颞下颌紊乱挂什么科hcv7jop9ns2r.cn 鸡内金有什么作用hcv9jop2ns0r.cn 膝关节退行性改变是什么意思hcv8jop3ns6r.cn 孕酮低有什么影响hcv9jop5ns1r.cn 痛风喝什么茶最好hcv9jop6ns5r.cn
峻字五行属什么hcv9jop5ns6r.cn 丝状疣用什么药inbungee.com 宝宝为什么老是吐奶hcv9jop6ns2r.cn 灬是什么意思mmeoe.com 孕妇吃什么蔬菜对胎儿好hcv9jop1ns5r.cn
为什么有的人怎么吃都不胖hcv9jop7ns1r.cn smile是什么意思hcv8jop2ns0r.cn 全身皮肤瘙痒是什么原因hcv8jop6ns1r.cn 做馒头用什么面粉好hcv8jop1ns3r.cn 雄性激素是什么hcv8jop1ns3r.cn
百度