Skip to content

Instantly share code, notes, and snippets.

@BenceSzalai
Last active December 9, 2023 23:22
Show Gist options
  • Save BenceSzalai/44456f9deb903f60c1295b08d6dcedb3 to your computer and use it in GitHub Desktop.
Save BenceSzalai/44456f9deb903f60c1295b08d6dcedb3 to your computer and use it in GitHub Desktop.
Deny public access to typical WordPress log files
# Deny access to sensiticve files
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} (.*(debug|error).*\.log|error_log)$ [NC]
RewriteRule .* - [F,L,NC]
</IfModule>
<IfModule !mod_rewrite.c>
<FilesMatch "(?i)(.*(debug|error).*\.log|error_log)$">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</FilesMatch>
</IfModule>
@BenceSzalai
Copy link
Author

BenceSzalai commented Dec 9, 2023

The <IfModule mod_rewrite.c> part is not strictly necessary to protect the files contents, but since <FilesMatch only acts if the file really exist, it can allow someone to detect which files are present. So whenever mod_rewrite is available, it is better to use that, even though it is a bit slower than FilesMatch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment