Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save matt-daniel-brown/7c9aded1841db0646142d5800bee3e25 to your computer and use it in GitHub Desktop.
Save matt-daniel-brown/7c9aded1841db0646142d5800bee3e25 to your computer and use it in GitHub Desktop.
Using strong pattern matching, this technique prevents external access to any file containing “.hta”, “.HTA”, or any case-insensitive combination thereof. To illustrate, this code will prevent access through any of the following requests: .htaccess, .HTACCESS, .hTaCcEsS, testFILE.htaccess, filename.HTACCESS, FILEROOT.hTaCcEsS.
# Strong pattern matching - method frome at Perishable Press:
# https://perishablepress.com/
# Using strong pattern matching, this technique prevents external access
# to any file containing “.hta”, “.HTA”, or any case-insensitive combination
# thereof, including... :
# - .htaccess
# - .HTACCESS
# - .hTaCcEsS
# - testFILE.htaccess
# - filename.HTACCESS
# - FILEROOT.hTaCcEsS
### ****************************************************************************
### STRONG HTACCESS PROTECTION
### ****************************************************************************
<Files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
# satisfy all
</Files>
# ~ credit: https://perishablepress.com/improve-site-security-by-protecting-htaccess-files/
# (From the article by Jeff Starr)
### ****************************************************************************
### A slightly better alternative (... I think...)
### ****************************************************************************
<FilesMatch "(.log|wp-config.php|.[hH][tT][aApP].*)">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
# ~ credit: https://perishablepress.com/improve-site-security-by-protecting-htaccess-files/
# (From user comments - Posted by @AskApache)
### ****************************************************************************
### Accomplish this using just a rewrite rule
### ****************************************************************************
# RewriteRule .ht[ap] - [NC,F]
# ~ credit: https://perishablepress.com/improve-site-security-by-protecting-htaccess-files/
# (From user comments - Posted by @AskApache)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment