UPDATES VIA   RSS  |  Email Get updates via feedburner Get updates via twitter
Home / Apache & mod_rewrite / Coding / Apache & ModRewrite: How…

Apache & ModRewrite: How to easily deny access to a folder with htaccess

Posted on 17. Jul, 2009 by in Apache & mod_rewrite, Coding

Working on a project right now I was looking for a solution to protect a folder containing template php files (includes in larger files). One solution would be to chmod the folder to avoid external meddling of one’s curious eyes. But working with Apache’s features I found out that it is more convenient to use the mod_rewrite feature to deny access to a folder and its content. Here’s the solution. In my case the folder I was trying to protect was templates so my code looked as following (simplified):


Options +FollowSymLinks
RewriteEngine on
#replace the word templates with the name of your own folder
RewriteRule ^/?templates/?(.*)?$ - [F,L]

Translate this post
                    
                    

Related posts:

  1. PHP: Get all files and folders from a directory (folder)
  2. WordPress: Best SEO iTranslator for WordPress, get free traffic from fully automated plugin script
  3. JavaScript: What if jQuery animation doesn’t fire/start?
  4. SQLite, MySQL, PHP: Ternary operator (IF() statement) in MySQL and SQLite