Apache: Disable php in a directory

前端 未结 2 1154
栀梦
栀梦 2021-01-15 19:52

I want to disable php in a directory on my server. I thought that setting Options -ExecCGI in httpd.conf would prevent php scripts from being executed, but obviously I am wr

相关标签:
2条回答
  • 2021-01-15 20:29

    you can do this with .htaccess file. you need to place a .htaccess file in the folder you don't want to execute the php with following htaccess code.

    <Files *.php>
    deny from all
    </Files>
    

    see here in more details http://www.wpbeginner.com/wp-tutorials/how-to-disable-php-execution-in-certain-wordpress-directories/

    Also you can Try to disable the engine option in your .htaccess file:

    php_flag engine off
    
    0 讨论(0)
  • 2021-01-15 20:48

    php_flag engine offonly works if you are using mod_php(as well as mod_php7.x) than php-fpm

    Seems you are using php-fpm, so add the further lines into httpd.conf:

    <Directory "C:/xampp/htdocs/(path_to_directory)/dirname">
    <FilesMatch ".+\.*$">
    SetHandler !
    </FilesMatch>
    </Directory>
    

    or these in .htaccess in the Directory you don't expect the execution of PHP:

    <FilesMatch ".+\.*$">
    SetHandler !
    </FilesMatch>
    

    I have tested it on an Unix Platform rather than a Windows, Hope it would help U.

    0 讨论(0)
提交回复
热议问题