see this

and this

<IfModule !mod_php5.c>
    <FilesMatch "\.php$">
        Order allow,deny
        Deny from all
        Allow from none

now i cant know mod_php5.c name becuase iam is not the server owner me is just have small host now is there any other way to do that this man i want deny access php file when the php is no longer here

  • Can you give some more details? It is hard to understand exactly what you want. Jan 8 '10 at 13:23
  • Checking for mod_php5 is very unreliable also because PHP sometimes runs as a normal CGI process... oh, and there are other httpds besides Apache, too.
    – user1686
    Jan 8 '10 at 16:41
  • It seems to me that the poster wants to disable access to .php files, but only when PHP is NOT enabled. Possibly in order to avoid outputting source code? Apr 20 '10 at 15:29

Put all files in another folder outside the server root, set a separate file configuring the path to that second folder; after that leave in your web root php files with the same name and include the real files on the fly.

An example for index.php:

    require '../mysite_config.inc.php';
    require INCDIR . 'index.php';

where mysite_config.inc.php contains:

    define('INCDIR', '../the_real_folder/');
  • +1 Any php files containing sensitive data (eg. MySQL Connection strings) should be in an include file in a directory that is outside the website root. Or at least in a directory that you deny access to regardless of whether PHP is working or not. You don't have to deny access to absolutely every php script, just the sensitive ones. Apr 20 '10 at 14:26

If you want to deny access to all PHP files, you could just use mod_rewrite:

RewriteEngine On
RewriteRule *.php accessdenied.html

And have a HTML file called "accessdenied.html" which displays an error, or replace "accessdenied.html" above with a link to the page you want the user to be redirected to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.