3

How do I hide Wordpress debug.log from search bots using .htaccess?

i.e: /wp-content/debug.log

Thanks.

1
  • If only restrict from search engines onnly nedd to disallow it in robots.txt. But this file shouldn't download by all, so you can protect it by auth: htaccesstools.com/articles/password-protection Commented Jan 15, 2018 at 13:11

1 Answer 1

11

I found the answer from another site which Wordfence had hidden for me.

<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_URI} ^/?wp\-content/+debug\.log$
        RewriteRule .* - [F,L,NC]
</IfModule>
<IfModule !mod_rewrite.c>
    <Files "debug.log">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order deny,allow
        Deny from all
    </IfModule>
    </Files>
</IfModule>
Sign up to request clarification or add additional context in comments.

2 Comments

What is the point of /? in the RewriteCond line? If we expect the server to not trim / characters before doing the match, it should be /*, to prevent access to example.com///wp-content... etc. If we expect the server to trim them, /? is not needed. I'm also not sure how much adding [NC] to the RewriteRule line helps, if the RewriteCond is case sensitive. Again, if we expect the server to be in case insensitive mode, than RewriteCond should have the [NC] flag. If we expect example.com/wp-content/DEBUG.log to give a 404, than [NC] is not needed on the RewriteRule line.
the point of /? is that if when you add the rules in .htaccess vs vhost conf. I can't remember which one removed the leading slash

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.