You can deny access to your site, or to a single directory, to visitors whose IP address is located in specific countries or continents. Everything is configured from the Apanel console: there are no files to modify. Remember the rule: what you check is blocked.
In short: in Hosting management, Website card, Folder protection, create the directory protection (/ for the whole site), then in the Restrictions by location tab check the countries or continents to block: checking means blocking.
Prerequisites
- Have access to your Apanel console.
- The directory to protect must already exist on the server: the Apanel console verifies its presence when you save.
What to know before you start
- The restriction applies to a directory. To cover the entire site, simply enter
/ as the path.
- The mechanism works as a blocklist, never as an allowlist.
- The change is immediate: the Apache configuration is regenerated and reloaded as soon as you save.
Step 1: create the directory protection
- Log in to your Apanel console.
- From the dashboard, click the name of your domain to open Hosting management.
- In the Website card, click Folder protection.
- Click Add.
- Fill in the two fields of the form:
| Field |
To enter |
Example |
| Path |
The directory to protect, relative to your site's root. / for the whole site. |
/espace-prive |
| Welcome message |
The text displayed in the browser's login window. |
Accès restreint |
- Click Save.
This is normal: the Restrictions by location and Restrictions by users tabs only appear after this first save. The protection must exist before rules can be attached to it.
Step 2: choose the countries or continents to block
- Open the Restrictions by location tab. Two lists of checkboxes are provided:
- Restrictions by continent: six entries (Africa, North America, South America, Asia, Europe, Oceania).
- Restrictions by country: the complete list of countries, in alphabetical order.
- Tick the continents and countries to block. Each list has Select all and Deselect all shortcuts. The two lists are cumulative: you can block an entire continent and add a few isolated countries.
- Click Save: the message Operation succeeded confirms the change has been applied.
The pitfall to know: checking means blocking.
The Apanel console indicates this at the top of the tab: "Visitors accessing from the country(ies) / continent(s) checked below will not have access to the directory."
By reflex, one checks Europe thinking "allow Europe", and blocks oneself. To allow only Europe, you must check everything except Europe.
Two use cases
How do I block a few specific countries?
This is the most common case, for example to reduce background noise from bots. In Restrictions by country, check only the relevant countries (China and Russia, for example), then save. The rest of the world continues to access the site normally.
How do I allow only one continent?
In Restrictions by continent, click on Select all, then uncheck the only continent you want to allow:
| Continent |
Checkbox |
Result |
| Africa |
Checked |
Blocked |
| North America |
Checked |
Blocked |
| South America |
Checked |
Blocked |
| Asia |
Checked |
Blocked |
| Europe |
Unchecked |
Allowed |
| Oceania |
Checked |
Blocked |
Can I also require a password?
Geographic restriction and password protection are two independent mechanisms that you can combine. The Restrictions by users tab allows you to create credentials: the directory will then require a username and password, in addition to the geographic filtering.
If you configure only location restrictions, without creating a user, the directory remains accessible to everyone, except for the countries and continents you have checked. It is a filter, not an authentication.
What does this protection not do?
- It is not foolproof. Localization relies on an IP address database: a visitor using a VPN or proxy located elsewhere is not filtered.
- It only concerns the web. FTP, email, and other services are not affected.
- It does not replace authentication. To protect sensitive data, add users or application-level authentication.
Troubleshooting
| Symptom |
Probable cause |
Solution |
| You are blocked although you are in Switzerland |
Europe, or Switzerland, was checked by mistake |
Restrictions by location tab, uncheck, then click Save |
| The path is rejected upon saving |
The directory does not yet exist on the server |
Create it first via FTP or from the File explorer, then try again |
| Nothing seems to change |
Page cached by the browser |
Retest in private browsing mode, or from another network |
Old .htaccess directives. Blocking by country used to be done with GeoIPEnable and SetEnvIf GEOIP_COUNTRY_CODE directives in a .htaccess file; the Apanel console now generates the equivalent configuration itself. If your site still contains these directives, contact support before removing them: we will verify with you that they can be removed without side effects.
Going further