WordPress Code Snippets

A fresh mix of code snippets and tutorials

Require HTTP 1.1 (and better) for POST


This quick .htaccess snippet requires that the user submit POST requests using only HTTP 1.1 and better.

To require only HTTP 1.1 or better for all POST requests, add this snippet to your site’s root .htaccess file.

Nothing needs changed or edited, simply plug-&-play. With this code in place, POST requests using HTTP 0.9 and 1.0 will be blocked via 403 Forbidden error. So only POST requests made using HTTP 1.1 and better (e.g., HTTP 2.0) will be permitted.

Require POST requests

Bonus! Here is a snippet that requires the user to make POST requests in order to access the specified file:

So for example, if you want to ensure that all requests for your contact form script are made via HTTP POST, add this snippet to .htaccess and edit /contact.php to match the path and file name of your actual script. And if the file is requested via Ajax, uncomment that last RewriteCond to allow the server to access the file via GET request.

Whitelist valid HTTP requests

Another bonus! Here is an .htaccess snippet that whitelists valid HTTP requests:

This code checks the SERVER_PROTOCOL variable and compares it against a whitelist that allows only HTTP requests versioned 0.9, 1.0, 1.1, or 2.0. This protects your site against malicious requests that are trying to game the system with invalid HTTP versions and other nonsense.

Learn more

.htaccess made easy

Show Support

Like our new Facebook Page to show support!