I've upgraded Apache 2.4 and would like to block an Ip this could be done by using the following in the .htaccess on Apache 2.2
Order Deny,Allow
Deny from 50.62.136.183
However how can I achieve the same in the .htaccess on Apache 2.4
I've upgraded Apache 2.4 and would like to block an Ip this could be done by using the following in the .htaccess on Apache 2.2
Order Deny,Allow
Deny from 50.62.136.183
However how can I achieve the same in the .htaccess on Apache 2.4
This is another acceptable syntax for .htaccess file:
This syntax is recommended for 2.4 because the order-deny syntax will not always work, as can be seen here http://httpd.apache.org/docs/2.4/upgrading.html
Apache 2.4 makes some big changes in the way it authorizing users.
Authorization components in Apache 2.4 can now use the Require syntax that was previously only available for authentication. This change simplifies the way to define authorization order. The rule sets previous to 2.4 rather could geth pretty complex. The rules in 2.4 are a more logical, specifying a default and then exceptions.
You are asking as a default for accepting traffic, but wish to block a specific IP, the rule would look something like this:
This rule will set a default policy of accepting all IP's except any request coming from the 111.111.111.111 IP address.
Examples of before and after Apache 2.4
Apache 2.2
Apache 2.4
Apache 2.2
Apache 2.4
The configuration of access control has changed, as you can read in http://httpd.apache.org/docs/2.4/upgrading.html#access so you should use the Require directive:
If you add that to your
.htaccess
file (or aDirectory
section) it should work as you asked.To Deny visitors by IP address you can put below entry in .htaccess
To block IP Range Example:
To Redirect unwanted visitor to another url:
Note: given IP address are Example IPs.
I had error 500 on ionos mutualised servers. The PB came from command order,allow,deny which not work anymore. I change for
<RequireAll> Require all granted Require not ip 50.62.136.183 </RequireAll>
I tried with my own complet IPV6 and it works ... but I can set just beginnin of IPV4 but not IPV6 !? (maybe, IPV6 doesn't work as IPV4 concerning first number determining a country, so no way to do that ...) So, this works<RequireAll> Require all granted Require not ip 50.62 </RequireAll>
But this doesn't work :<RequireAll> Require all granted Require not ip 20a6:5bd2 </RequireAll>