How to prevent access to files of certain extensions in .htaccess?
  • go then htaccess.net.ru and start reading! - Palmervan

2 answers 2

<FilesMatch "config.php"> Order Deny,Allow Deny from all </FilesMatch> 

denies access to the config.php file

 <FilesMatch ".(gif|jpe?g|png)$"> Order Deny,Allow Deny from all </Files> 

ban on pictures

  • It works, but not correctly. Now does not open normal pages. site.com/page - Oleg
  • 2
    If you prohibit pictures, they will not be displayed on the page, will it? - Zowie
  • I banned php - Oleg
  • 6
    You have forbidden to open pkhp and are surprised that pkhp does not open? Enchanting. - Sh4dow
  • :) - Damon

I need to forbid a direct call to php, and allow the call via include.

.htaccess does not help here.

Need something like:

index.php :

 $GLOBALS['_INC_OTHER'] = 1; include('other.php'); 

other.php :

 if (empty($GLOBALS['_INC_OTHER'])) exit; 

As a result, the file other.php can only be connected via index.php.

  • This I knew, was looking for another, simpler way. - Oleg
  • I'm afraid that you will not find anything simpler - Alex Kapustin