简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM