Forum Moderators: phranque
If this is a file that is 'included' by another script, then you can place it in a Web-inaccessible directory, as you have arranged with the 'Deny from all' bit. Since a 'file include' is accomplished with a server-internal read, and 'Deny from all' affects only (externally-invoked) HTTP requests and not internal server operations, that should work.
We don't know what you do and don't know, so if you don't say it, then don't take offense if other members assume you don't know it, please.
> but it doesn't work
Please explain, in detail, what that means: How did you test? What were the results? How did those results differ from your expectations? Did you flush your browser cache before testing, so as to avoid getting a cached page instead of requesting a fresh copy from your server? The solution lies in the details.
Jim
Eg, disallowing them to see what happens if they go to this file:
[lalala...] . something/inc/folder/a-non-public-php-file.php
Hence, disallowing direct access to the script from their browser.
Kind regards,
R.
<Limit GET POST>
order deny,allow
deny from all
</Limit>
That will stop requests for files as well as directory listings even if "Options +Indexes" is also in there. This will deny requests for ALL files, not just php files. If someone knows how to limit this to just certain file types from within the .htaccess file, do tell.
Also, if you have access to the standard apache config files, then much more can be done, but in a shared environment (like I have) this is not an option.
<FilesMatch "\.(inc¦cfg¦pwd¦fcn¦rsrc¦tmp¦js¦css¦cron¦bck¦bld¦xml¦mnu)\.php$">
order deny,allow
deny from all
</FilesMatch>
<FilesMatch "\.(inc¦cfg¦pwd¦fcn¦rsrc¦tmp¦js¦css¦cron¦bck¦bld¦xml¦mnu)\.php$">
order deny,allow
deny from all
</FilesMatch>
It only works on Apache 2. The pattern is set to stop people from accessing your php files anywhere under this .htaccess file and the pattern includes prefixes (that i use to differentiate php files from each other).
Pattern: \.(inc¦cfg¦pwd¦fcn¦rsrc¦tmp¦js¦css¦cron¦bck¦bld¦xml¦mnu)\.php$ > \. (dot for the extension) inc or cfg or ... (for prefix) \. (dot) php (obv) $ (end of string!)
Enjoy!