Get a free website with any plan

See how
CPANEL

Allowing or denying IPs in .htaccess

Last updated

IN SHORT

On Flashcloud hosting, you allow or block IP addresses using Apache Require directives in your .htaccess file. Adding Require not ip stops unwanted visitors, while Require ip restricts access to approved addresses only. Apache processes these rules before PHP runs, so blocked requests never touch your application code.

To block an IP address from reaching your site, add Require not ip 123.45.67.89 inside a <RequireAll> block in your .htaccess file. To allow only specific IPs and block everyone else, use Require ip with the addresses you want to let through. Both directives work on Apache, which is what handles requests before PHP ever runs, so a blocked IP never touches your application code.

The exact syntax depends on which Apache version your directives target. Most current hosting stacks use the modern mod_authz_core syntax shown below, not the older Order, Allow, Deny syntax from Apache 2.2.

Blocking one or more IPs

To deny specific addresses while allowing everyone else, place this at the top of the .htaccess file in the directory you want protected:

<RequireAll>
    Require all granted
    Require not ip 123.45.67.89
    Require not ip 98.76.54.0/24
</RequireAll>

Each Require not ip line adds one blocked address or range. The /24 notation blocks an entire subnet, in this case all 256 addresses from 98.76.54.0 to 98.76.54.255. Use a narrower or wider prefix depending on how much of the range you actually need to block.

Allowing only specific IPs

To restrict a directory so only certain addresses can reach it, invert the logic:

<RequireAll>
    Require ip 123.45.67.89
    Require ip 10.0.0.0/8
</RequireAll>

Anything not explicitly listed gets a 403 response. This pattern is common for staging environments, admin folders, or internal tools you don't want indexed or reached by the public.

Combining allow rules with authentication

You can pair an IP allow list with HTTP authentication so a request needs to satisfy both, or either. Replace <RequireAll> with <RequireAny> if you want IP-based access OR a valid login to count as authorized; keep <RequireAll> if both conditions must be true.

Where to put the file

The rules apply to the directory containing the .htaccess file and everything below it. If you want the restriction site-wide, edit the .htaccess in your domain's document root. If you only want it on one folder, like /admin, put a separate .htaccess file inside that folder instead. You can edit these files directly with the File Manager tile in the portal, or through an FTP client using credentials from FTP Accounts.

Common mistakes

  • Locking yourself out. If you're allowing specific IPs and your own address changes (common on home internet or mobile connections), you'll get a 403 on your own site. Check your current public IP before saving, and add a wider range if your ISP rotates addresses frequently.
  • Mixing old and new syntax. Order, Allow, Deny and Require directives don't combine cleanly. Pick one syntax and use it consistently in a given block.
  • Forgetting subnets. Blocking a single IP does nothing if the visitor is on a dynamic address or behind a proxy that rotates addresses. A single-IP block is a short-term fix, not a lasting one.
  • Applying it to the wrong directory. Rules cascade downward, not upward. A rule in a subfolder's .htaccess doesn't protect the parent directory.

When IP blocking isn't the right tool

Manual IP blocks in .htaccess work well for a known, stable set of addresses: a specific bad actor, an internal office IP range, a partner's server. They don't scale well against distributed abuse, botnets, or attackers who rotate addresses, since you'd be editing the file constantly. For ongoing malicious traffic, active scanning, or brute-force attempts, Imunify360's web application firewall handles that automatically at the account level and adapts as attack patterns change, which is a better fit than a hand-maintained block list.

If you've locked yourself out of your own site and can't edit the file over FTP either, or you're not sure whether a rule you added is causing a 403 for legitimate visitors, open a ticket from the portal's Support section and our team can help.

Common questions

Why am I getting a 403 error on my own site?

You locked yourself out because your IP address changed. Home and mobile connections rotate public IPs often. Update your .htaccess file with your current IP address or add a wider subnet range.

Where do I put the .htaccess file to block an IP?

Place the file in your domain's document root for site-wide protection. If you want to protect a single directory like /admin, place it inside that specific folder. Rules apply to the folder holding the file and cascade downward.

Can I block a whole range of IP addresses at once?

Yes, you can add subnet notation like /24 to a Require not ip directive. For example, a /24 prefix blocks all 256 addresses in that range. This prevents visitors on rotating dynamic addresses or proxies from bypassing single-IP blocks.

Can I use old Order Allow Deny rules?

Avoid mixing old and new formats. Current hosting stacks use modern mod_authz_core Require syntax instead of Apache 2.2 syntax. The two formats do not combine cleanly in the same block, so pick one and stick to it.

CAN'T FIND IT?

Real humans answer fast.

Hosting with us? Open a ticket and a real person replies - no scripts, no upsells. Still choosing a host? The same team is included with every plan, from day one.