Use Deny from all only on Apache 2.2 or a deliberately maintained compatibility configuration. On a current Apache 2.4 server, the equivalent rule is Require all denied. To block selected addresses instead of everyone, combine a positive grant with negated IP requirements in a <RequireAll> block. The correct directive depends on the Apache version, the directory covered by the file, and whether the host permits these directives in .htaccess.
Antihost offers managed WordPress hosting with free migration, one-click staging and a 14-day free trial.
Choose the rule that matches your Apache version
Deny from belongs to Apache 2.2’s access-control syntax. Apache 2.2 uses Order, Allow, and Deny directives to decide whether a client may reach a resource. Apache 2.4 uses the authorization system built around Require. These syntaxes are not interchangeable, even though they can express a similar policy.
As an Amazon Associate I earn from qualifying purchases.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitches| Server or configuration | Block every client | Block selected clients | How the decision is evaluated |
|---|---|---|---|
| Apache 2.2 | Order Allow,Deny |
Order Allow,Deny |
Order controls the sequence in which allow and deny rules are evaluated. |
| Apache 2.4 | Require all denied |
<RequireAll> |
Authorization is expressed with Require; a negated requirement must accompany a positive requirement. |
If you do not know the server version, ask the hosting provider or inspect the server’s Apache information through the control panel or administrator account. Do not paste a 2.2 example into a 2.4-only configuration and assume it has the same effect.
What a .htaccess rule actually affects
Apache reads .htaccess in per-directory context. A file placed in a document-root directory governs that directory and the URL paths below it, subject to the server’s inheritance and configuration rules. A file in a subdirectory narrows the policy to that location. It does not automatically become a server-wide firewall rule.
#1 Best Overall
The rule normally applies to all HTTP methods handled in that directory, not merely GET. A denial therefore affects requests such as POST, PUT, or DELETE when Apache processes them under the same directory context. Application-level routing can still change what happens after Apache has made its authorization decision.
The administrator must permit the relevant override class with AllowOverride. If overrides are disabled, Apache can ignore or reject the directive instead of enforcing it. The exact override class depends on the directive and the host’s configuration. Shared hosting users may need support to enable access-control directives.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallKeep a recovery path before testing a rule that denies everyone. If the file contains a syntax error or an unsupported directive, Apache may return server errors or make the directory unavailable. Keep an administrator-controlled route, console, deployment account, or backup copy that can remove the file without relying on the blocked web request.
Block every visitor on Apache 2.2
Use the legacy complete-denial pattern
Order Allow,Deny
Deny from all
Placed in a directory’s .htaccess, this denies every client reaching that directory scope. Order Allow,Deny tells Apache to evaluate allow rules first and deny rules second. Because the final deny rule matches all clients, no client is left authorized by this policy.
Understand why Order matters
In Apache 2.2, changing the order changes the result when a request matches both an allow and a deny rule. The order is therefore part of the access policy, not decorative syntax. A compatibility file that contains only Deny from all may behave differently from a file that also contains inherited or local Allow directives. Review the complete per-directory configuration before changing the order.
Rank #2
- Used Book in Good Condition
When this form is appropriate
Use this pattern when you are maintaining an Apache 2.2 deployment or a configuration intentionally using the legacy compatibility module. It is not the preferred form for a native Apache 2.4 configuration. On a current server, use the 2.4 authorization model instead of adding more legacy directives.
Block every visitor on Apache 2.4
Use Require all denied
Require all denied
Apache documents Require all denied as the complete-denial rule. It expresses the policy directly in the 2.4 authorization system: no client satisfies the requirement. Put it in the .htaccess directory whose files and paths must be inaccessible.
Do not combine it casually with a legacy block
Apache 2.4 installations can load mod_access_compat to recognize older Order, Allow from, and Deny from directives. Compatibility support is useful while migrating an old site, but it does not make the two policy languages interchangeable. Prefer Require for new rules, and migrate deliberately after checking the complete configuration and inheritance behavior.
Block specific IP addresses or subnets on Apache 2.4
Start with a positive authorization and add negated IP requirements
<RequireAll>
Require all granted
Require not ip 203.0.113.42
Require not ip 2001:db8:1234::/48
</RequireAll>
This policy grants access generally, then excludes the listed IPv4 address and IPv6 network. The first address is a single IPv4 client. The second is an IPv6 CIDR range. Add one Require not ip line for each address or network that must be rejected.
A negated requirement cannot make a complete authorization decision by itself. Require not ip ... must be combined with a positive requirement such as Require all granted inside <RequireAll>. Without that positive requirement, Apache has no affirmative authorization result for clients that are not denied.
IP formats accepted by Require ip
Apache 2.4’s Require ip accepts full addresses, partial IPv4 prefixes, CIDR or netmask ranges, and IPv6 forms. Use the notation that clearly identifies the intended network boundary. For a single address, use the complete address. For a managed network, use the documented CIDR prefix rather than an informal guess.
- Single IPv4 address:
Require not ip 203.0.113.42 - IPv6 network:
Require not ip 2001:db8:1234::/48 - Multiple exclusions: add separate negated requirements in the same
<RequireAll>block.
The example addresses use documentation ranges. Replace them with the real addresses that your policy identifies, and verify the source address Apache actually sees when a proxy, load balancer, or CDN sits in front of the server.
Block specific IP addresses on Apache 2.2
Use the legacy allow-all, deny-exceptions pattern
Order Allow,Deny
Allow from all
Deny from 203.0.113.42 198.51.100.
This allows clients by default and then denies the listed IPv4 address and the partial IPv4 prefix beginning with 198.51.100.. The trailing dot illustrates the legacy partial-prefix form. The exact result still depends on the server’s Apache 2.2 configuration and the active Order policy, so check for inherited directives before deploying it.
Do not translate syntax by word substitution
Replacing Deny from with Require not ip without adding the required positive authorization is incomplete on Apache 2.4. Conversely, copying an Apache 2.4 <RequireAll> block into a server that only supports the 2.2 access-control module will fail. Identify the version and loaded modules first.
Free tools Windows power users keep installed
One-click scans. No signup required.
Directory scope versus broader server configuration
Use .htaccess for a local directory policy
A rule in /site/private/.htaccess applies to that directory’s URL path and descendants governed by Apache’s per-directory processing. This is useful when one area of a site must be closed while the rest remains public. Place the rule as close as practical to the content it protects, and check whether a nested .htaccess adds or changes authorization behavior.
Rank #4
Use server or virtual-host configuration for global policies
A server administrator can express broader policies in the main Apache configuration or a virtual-host definition. That approach avoids per-request directory-file lookups and gives the administrator one place to audit the rule, but it requires configuration access. A site owner who only has file access cannot assume that a root-level .htaccess rule has the same scope as a virtual-host policy.
Remember the override prerequisite
If AllowOverride does not permit the authorization directives in a directory, Apache will not apply them as intended. Depending on the host’s setup, the result may be an ignored rule or an error response. Ask the administrator which override class is enabled rather than repeatedly editing a file that the server is not allowed to honor.
Step-by-step deployment checklist
- Define the target. Decide whether the policy should block every client or only named addresses, and identify the exact directory and URL paths that must be affected.
- Confirm the Apache version. Use the 2.2 syntax only for an Apache 2.2 or intentional compatibility configuration. Use
Requireon native Apache 2.4. - Check administrative access. Keep a console, deployment route, or trusted management path that can restore the file if the rule locks out ordinary web access.
- Back up the existing file. Preserve the current
.htaccess, including comments and unrelated rewrite rules, before editing. A replacement that deletes other directives can break routing even when the access rule is valid. - Insert the smallest policy that meets the goal. Use
Require all deniedor the two-line 2.2 complete-denial block for a full lockout. Use the IP exclusion block when most visitors should remain allowed. - Validate the syntax. Use the configuration-test process supplied by the host or administrator. For a server-managed installation, run the approved Apache configuration test before reloading; shared hosting users should ask the host to perform that check.
- Test from an allowed client. For an IP exclusion policy, request the protected URL from an address that should remain permitted and confirm the expected response.
- Test from a denied client. Use the blocked address or a controlled test network. Confirm that the denial occurs at the intended directory and does not accidentally expose a nested path.
- Review the error log. If the site returns a server error or Apache reports an unknown directive, inspect the error log and remove or correct the unsupported rule through the recovery path.
- Document the scope. Record the Apache version, directory, addresses, date, and reason for the policy so a later administrator does not replace a working 2.4 rule with an obsolete 2.2 example.
Common failure modes and fixes
The rule appears to do nothing
- The host may have disabled the required
AllowOverrideclass. Ask the administrator to enable the relevant override or move the policy into the virtual-host configuration. - The file may not be in the directory that governs the requested URL. Trace the URL to its document-root and nested directories.
- A proxy or load balancer may be the client Apache sees. Verify the address in Apache’s logs before writing an IP rule.
- A later or inherited authorization rule may change the effective policy. Review the complete per-directory and virtual-host configuration.
Apache returns a 500-level error after editing
An unsupported directive, malformed block, or version mismatch can make the directory unavailable. Restore the backup through the administrative path, inspect the Apache error log, and run the host’s configuration test. On Apache 2.4, check that every negated IP requirement is inside a valid authorization structure with a positive requirement. On Apache 2.2, check the spelling and placement of Order, Allow from, and Deny from.
Recommended Free Tools
An administrator is locked out
A complete-denial rule intentionally blocks every client, including the person who installed it. Remove or narrow the rule through a console or other out-of-band access path. Do not rely on an HTTP request from the same blocked network to repair the file.
A supposedly blocked address still reaches the site
Check whether the request is reaching a different virtual host, a cached response, a reverse proxy, or a nested path with a separate policy. Confirm the source address Apache records and ensure the address is written in the correct IPv4, IPv6, CIDR, or legacy-prefix form. If the address changes because of a proxy, an IP-only rule may need to be applied at the proxy layer instead.
Best Value
- Used Book in Good Condition
Hostname rules, IP rules, and policy precision
Apache’s host-access controls can restrict access by hostname or IP address. IP rules are generally easier to audit because they match explicit network values; hostname-based decisions depend on name resolution and the names presented by the client or resolved by the server. Use an IP or CIDR form when the policy is really about a network boundary, and document the reason for any hostname-based policy.
For a single machine, use one full address. For a provider, office, or managed network, use the exact subnet supplied by that network’s administrator. A partial IPv4 prefix in the legacy syntax and a CIDR range in Apache 2.4 are not interchangeable spellings; select the notation supported by the server version and verify that it covers exactly the intended clients.
Security and operational limits
Access denial in .htaccess is an HTTP authorization control, not a replacement for a network firewall, account security, rate limiting, or application authentication. It can stop Apache from serving the directory to matching clients, but it does not remove content from backups, prevent access through another service, or identify a user behind a shared or changing address.
Blocking an address can also block legitimate users who share a network, use carrier-grade NAT, or receive a recycled address. Prefer the narrowest address or subnet that meets the documented objective. When a temporary lockout is required, record an owner and review date so an emergency rule does not become permanent by accident.
A complete denial is appropriate for a maintenance directory, an unpublished site area, or a deliberately private path when an administrator has a separate access route. It is risky on a public document root because it immediately removes every visitor, crawler, API client, and administrator using ordinary HTTP.
Migrating from Deny from to Apache 2.4
- Inventory every
Order,Allow from, andDeny fromdirective in the server and its.htaccessfiles. - Map each policy to its intent: deny everyone, allow everyone except selected IPs, or permit only a defined set.
- Rewrite the intent with Apache 2.4
Requiredirectives. A complete denial becomesRequire all denied; an exclusion policy uses<RequireAll>,Require all granted, and one or moreRequire not iplines. - Test nested directories and all relevant HTTP methods after migration. The per-directory scope should remain the same unless you intentionally change it.
- Remove legacy directives only after the new policy has been validated and the compatibility dependency is no longer needed.
mod_access_compat can support older directives during a transition, but leaving mixed syntax indefinitely makes future troubleshooting harder. Treat compatibility as a migration aid, not as a reason to present 2.2 and 2.4 examples as equivalent.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Quick reference examples
Apache 2.2: deny everyone
Order Allow,Deny
Deny from all
Apache 2.4: deny everyone
Require all denied
Apache 2.4: allow everyone except one IPv4 address and one IPv6 network
<RequireAll>
Require all granted
Require not ip 203.0.113.42
Require not ip 2001:db8:1234::/48
</RequireAll>
Apache 2.2: allow everyone except an address and legacy partial prefix
Order Allow,Deny
Allow from all
Deny from 203.0.113.42 198.51.100.
Use only the block that matches the server’s authorization system. Keep the rule in the directory whose URL scope you intend to protect, validate it through the host’s configuration process, and retain a way to recover the file when testing a complete denial.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




