拒绝访问除子目录中的文件以外的所有文件

I am trying to restrict access to all files in my home directory, then to allow only one main php file from a subdirectory using one .htaccess file, but it does not work as expected. It shows only "Forbidden" for every request. How to make it work as expected?

Now I am using :

order allow,deny

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$ [OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /path_to_file/index.php [QSA]

You can just forward all requests to that particular file. Put this in your root .htaccess:

RewriteEngine On

RewriteCond %{REQUEST_URI} !/subdir/file\.php$ [NC]
RewriteRule ^ /subdir/file.php [QSA]