Htaccess Deny Access to File Extension Example
Hi Dev,
In this short tutorial we will cover an htaccess deny access to file extension. let’s discuss about htaccess restrict access to file extension. This article will give you simple example of htaccess deny access to php files in uploads folder. step by step explain prevent direct access to php file htaccess. You just need to some step to done htaccess disable file extension access.
Sometime we are creating "uploads" directory and all files will store on that directory that user uploaded. so maybe someone upload some script then it can hack our website as well. so we can prevent this type of file extension access from url using .htaccess.
we can deny to access by file extension like php, rb, py etc. as like bellow.
let's see bellow solutions:
Example 1:
you can not access php, rb, py files inside that folder:
.htaccess
RewriteEngine On
RewriteRule ^uploads/.*\.(php|rb|py)$ - [F,L,NC]
you can not access following files:
/uploads/test.php
/uploads/demo.php
/uploads/test2.php
Example 2:
you can not access php, rb, py files inside that folder:
.htaccess
<FilesMatch "\.(?:inc|php|py|rb)$">
Order allow,deny
Deny from all
</FilesMatch>
you can not access following files:
/test.php
/uploads/demo.php
/uploads/test2.php
i hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Restrict Access to a Folder with htaccess?
- How to Whitelist/Allow IP Address using .htaccess File?
- How to Restrict/Block IP Address using .htaccess File?
- Laravel Connect Remote Database using SSH Tunnel Example
- How to Install PHP in Ubuntu Server?
- How to Deny Access to a File using .htaccess?
- How to Connect SSH using ppk File Ubuntu?
- Codeigniter Remove index.php form URL using htaccess