InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Apache tutorials

  • AWStats on Ubuntu
  • ApacheBench - load testing
  • Auth to a location or directory
  • Block directory access using htaccess 404
  • Different expire Headers for multiple images
  • Disable directory listing
  • List loaded modules
  • Log Content-Type in access log
  • Log latency and host in apache log
  • Monitoring using mod_status
  • Python to analyze bots in logs
  • Remove php extension from url
  • egrep and access log
  • log custom data in apache access log
  • mod_rewrite
  • top IP list from access log
 
  • Home
  • > Tutorials
  • > Web Development
  • > Apache

Block directory access using htaccess 404

By admin on Nov 14, 2015

RewriteRule in Apache .htaccess is a convenient way to block directory access to a directory in your Apache document root. This can be useful to avoid accidental access to some content in these directories. Here is the config you can use in .htaccess in the desired directory.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^.*  - [R=404,L]
</IfModule>

Note that you don’t need to restart apache after .htaccess changes. R=404 will set the HTTP status code to 404. L is used to stop processing more mod_rewrite rules.

Here is how the a page having blocked directory looks like in Chrome. We are using directory _internal just for the purpose of this tutorial.
apache-htaccess-404-in-chrome

Suggested posts:

  1. CSS – inline-block and baseline alignment
  2. Disable directory listing in apache
  3. PHP sort associative array using custom compare function
  4. How to get docker container IP
  5. How to list git branches
  6. Linux – find files containing specific text
  7. Using Google analytics SDK v2 for android app real time tracking
  8. PHP execute command and capture shell exit status
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Apache, Linux, mod_rewrite, Tutorials, Ubuntu Linux, Web Development
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress