apache指定目录禁止执行php文件

五月 08, 2019 | views
Comments 0

本文章来给大家介绍在apache环境中如何禁止指定目录执行php,htm,asp文件的方法,下面我介绍利用apache,hatccess的方法,同时还有nginx中的配置方法。

htaccess禁止php,htm

php_flag engine off


  1. <Files  ~ ".php"
  2. order allow,deny 
  3. deny from all 
  4. </Files> 
  5. <Files  ~ ".htm"
  6. order allow,deny 
  7. deny from all 
  8. </Files> 
  9. <Files  ~ ".html"
  10. order allow,deny 
  11. deny from all 
  12. </Files> 
  13. <FilesMatch (.*).htm$>   
  14.     order allow,deny     
  15.     deny from all     
  16. </FilesMatch> 
  17. <FilesMatch (.*).html$>   
  18.     order allow,deny     
  19.     deny from all     
  20. </FilesMatch> 

在apache中直接定义



  1. <Directory /usr/local/apache/htdocs/bbs/data> 
  2. php_flag engine off 
  3. </Directory> 
  4. <Directory ~ "^/home/centos/web/data"
  5.  <Files ~ ".php"
  6.  Order allow,deny 
  7.  Deny from all 
  8.  </Files> 
  9. </Directory> 

nginx



  1. location /data/ { 
  2. location ~ .*.(php)?$ { 
  3. deny all; 



zend