Search code examples
apacheapache-config

prevent *.bak *.inc file upload from a apache server


Is it possible to prevent people from seeing files like .bak from am apache directory ? If there is a request for the url (http://foo.com/bar.bak), it'd be good to have a 404 error, and prevent anybody to upload the file.


Solution

  • Now that I know the answer, here it is : one of them is to use RewriteRule in the httpd.conf. – Cedric 14 secs ago edit Now that I know the answer, here it is : one of them is to use RewriteRule in the httpd.conf.

    RewriteEngine On # Turn on the rewriting engine RewriteRule
    
    RewriteRule   ^(.*(\.(html|htm|gif|js|jpg|jpeg|php|css)|\/))$    $1  [L,NC]
    # do not do anything (no rewriting), but don't execute the next rule
    #("NC", tells Apache that this rule should be case-insensitive, and "L" tells Apache not to process any more rules if this one is used.)
    
    RewriteRule   ^.*$    /  [NC,R] # rewrite all the other urls to /
    

    This is the main idea. Please, modify the first regex to your needs ! (as urls like foo?bar=obu won't work, nor foo/bar)