Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to block direct requests to php files in specified directory?

I have a master folder where I hold all of my resources such as js, css, images, etc. called /resources/.

In /resources/, I have php files I include on pages of my website, however, they're currently directly accessible if entered into the browser.

Is there a way for me to use .htaccess in that directory to prevent direct requests to any files of certain extensions such as PHP? Hotlinking prevention isn't really what I'm looking for. I just need a way to kill any sort of direct request to these PHP files(in the /resources/ directory specifically) made by anything other than the website itself.

Any help is appreciated. Thank you very much.

like image 534
popsicle Avatar asked Nov 29 '25 20:11

popsicle


1 Answers

Add a .htaccess in your /resources/ folder containing the following

<Files ~ "\.php$">
  Order allow,deny
  Deny from all
</Files>

It should prevent access to all .php files

like image 86
emartel Avatar answered Dec 02 '25 09:12

emartel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!