How to correctly configure `.htaccess` for LiteSpeed Web Server (v6.3.4) to allow by range/ip

#1
Hello everyone,



I’m currently hosting a website on LiteSpeed Web Server Enterprise v6.3.4 , and I want to properly configure my .htaccess file for better security.



My goal is to block all direct IP access and allow traffic only from:



- Cloudflare IP ranges (since my site is behind Cloudflare)

- Google bots (for indexing)

- cron-job.org (for scheduled tasks)



I tried a few rules :

Code:
```
Deny from all

# Allow specific IPv4 addresses
Allow from 116.203.134.67
Allow from 116.203.129.16
....```

```
ErrorDocument 403 "Not Allowed"
Deny from all

### Cloudflare IPs ###

Allow from 103.21.244.0/22
Allow from 103.22.200.0/22
Allow from 103.31.4.0/22
....```

```
# Allow Cloudflare IPv4 ranges
Require ip 173.245.48.0/20
Require ip 103.21.244.0/22
....```

```
Require all denied

# Allow specific IPv4 addresses
Require ip 116.203.134.67
Require ip 116.203.129.16
Require ip 23.88.105.37
....```

```
Order Deny,Allow
Deny from all

# Allow specific IPv4 addresses
Allow from 116.203.134.67
Allow from 116.203.129.16
Allow from 23.88.105.37
...
```

```
<FilesMatch ".*">
    # Allow specific IPv4 addresses
    Require ip 116.203.134.67
    Require ip 116.203.129.16
    Require ip 23.88.105.37
.....
```

```
<RequireAny>
    # Allow specific IPv4 addresses
    Require ip 116.203.134.67
    Require ip 116.203.129.16
    Require ip 23.88.105.37
....
```
but it seems LiteSpeed behaves slightly differently from Apache ( all either aren't applied or blocking everything ), and I’m not sure what’s the correct syntax or best practice here.



Can anyone share a working example or guide me on how to correctly set up the .htaccess file for this scenario?



I’d like to make sure legitimate requests from Cloudflare and Googlebot aren’t blocked, while all other direct IP access is denied.


Thanks in advance for your help!
 
Top