Preventing PHP from executing in some directories


#1

I’m trying to disable all scripts from running in a directory and all of its children. I think the fact that I’m a legacy PHP4 user may be complicating things. I’ve got the following in the .htaccess file for the top directory of the directory tree where I want script execution disabled:

RemoveType application/x-httpd-php .php
AddType text/plain .php
RemoveHandler cgi-script .cgi .pl .py .php
RemoveHandler php-cgi .php4 .pcgi4 .php
RemoveHandler php5-cgi .php

I’ve had a few back and forth emails with support over the last couple of days and adding the AddType line is the latest suggestion from support, which had no effect.

Has anyone had any success with disabling scripts from running in specific directories using .htaccess?


#2

Use mod_rewrite instead.

[code]-- .htaccess located in /home/username/domain/src –
RewriteEngine On
RewriteBase /src/

Condition - requesting a file that exists

RewriteCond %{REQUEST_FILENAME} -f

Rule - match requests ending in the .php extension

RewriteRule .php$ /src/php-source.cgi [L][/code][code]-- php-source.cgi located in /home/username/domain/src –
#!/bin/bash
NL=$’\n’

Determine file path

FILEPATH="${DOCUMENT_ROOT}/${REQUEST_URI}"

Output HTTP headers

echo "Content-Type: text/plain"
echo $NL

Output document header

echo "Reading source file: ${REQUEST_URI}"
echo $NL

Use cat to read the file

exec cat $FILEPATH[/code]

Customer since 2000 :cool: openvein.org