Sysadmins of the North
Share now!


WordPress .htaccess security best practices in Apache 2.4.6+

Apache Access Control done right, ‘Allow/Deny from all’ versus ‘Require All Granted/Denied’

Since Apache 2.4.6, a new module is used to configure and set up access control for websites: mod_authz_core. This means you have to use a different syntax for allowing or blocking hosts and IP addresses to your website. But unfortunately, old documentation is never updated and people even still write blog posts using that old syntax, leaving you with an unprotected website. Not what you had in mind, now is it?…

I see it all to often: blog post telling you to use the following snippet in a .htaccess file to secure / protect a file like wp-config.php:

<Files wp-config.php>
	Order Allow,Deny
	Deny from all

This is wrong!

Unfortunately this doesn’t work anymore with Apache 2.4.6 and higher! And I find it hard to believe so called “WordPress Security” companies still write posts explaining the old, non-functional, syntax without even mentioning the new syntax…

Satisfy, Order, Deny and Allow have all been deprecated and replaced with new Require directives.

Yes, there is Apache’s mod_access_compat, that provides compatibility for old directives like Order, Allow, Deny and Satisfy. But depending on such a module is not recommended, since it’s deprecated by mod_authz_host:

Access authorization in Apache 2.4.6

So now, for once and for all: how to use the new Apache 2.4.6+ mod_authz_host syntax in your .htaccess:

# Protect wp-config.php
<Files wp-config.php>
	Require all denied
	Require ip # substitute with your IP address

For compatibility with older Apache versions, you can wrap this up in a condition:

<Files wp-config.php>
	# Apache 2.2
	<IfModule !mod_authz_core.c>
		Order Deny,Allow
		Deny from all
		Allow from

	# Apache 2.4
	<IfModule mod_authz_core.c>
		Require all denied
		Require ip

Note: by using an .htaccess file you’d normally leave Nginx and IIS web servers unprotected! You can use .htaccess in IIS though, but don’t rely on just .htaccess files for your website defense.

This may interest you:   Install WordPress plugins without WP-admin access

Psst, here are 7 snippets to use .htaccess as a Web Application Firewall. However, .htaccess files should not be used for security restrictions.

buy me a coffee
Buy Me A Coffee

About the Author Jan Reilink

My name is Jan. I am not a hacker, coder, developer, programmer or guru. I am merely a system administrator, doing my daily thing at Vevida in the Netherlands. With over 15 years of experience, my specialties include Windows Server, IIS, Linux (CentOS, Debian), security, PHP, WordPress, websites & optimization. Want to support me and donate? Use this link:

follow me on:

Thank you!

Leave a Comment:

Add Your Reply
Skip to content