Blocking access to the site using a .htaccess file

Description of blocking access to the site using the .htaccess configuration file

.htaccess is a configuration file for the Apache web server. It allows you to set additional parameters and permissions for individual directories (folders) without modifying the main server configuration file. With .htaccess, you can control access to directories and files, redefine file types, set encoding, and more.

Note

cPanel is used as the control panel for all shared hosting accounts.

If a user tries to access a page restricted by .htaccess, they will see a service page with a 404 error code.

To edit the file, go to Files → File Manager.

file

Open the public_html directory.

file

By default, the .htaccess file is hidden. To display it, click Settings and check the box Show Hidden Files (dotfiles).

file

Then select the .htaccess file and click Edit.

file

In the popup window, click Disable Encoding Check, then click Edit.

file

After making your changes, click Save Changes.

file

How to block access to the entire site

Each directive has its own meaning:

  • Order — defines the order of rule execution.
  • Allow — grants access.
  • Deny — denies access.

To completely block access to the site, use:

deny from all # Denies access to the site for all IP addresses

How to allow access from a specific IP

To make the site available only from a single IP address:

order deny,allow # Defines the execution order: allow is applied after deny
deny from all # Denies access to the site for all IP addresses
allow from XXX.XXX.XXX.XXX # Grants access for the specified IP. Multiple IPs can be listed, separated by spaces.

How to block access from a specific IP

To deny access only for one IP address:

deny from XXX.XXX.XXX.XXX # Blocks access for the specified IP. Multiple IPs can be listed, separated by spaces.

How to restrict access to a specific file

You can apply different rules for different files. For example, to restrict access to wp-config.php for everyone except your IP:

<Files wp-config.php>
order deny,allow
deny from all
allow from XXX.XXX.XXX.XXX
</Files>

Similarly, you can protect the .htaccess file itself:

<Files .htaccess>
order deny,allow
deny from all
allow from XXX.XXX.XXX.XXX
</Files>

Help

If you encounter difficulties or need assistance, please create a request via our ticket system, and we’ll be happy to help you.

Need help?Our engineers will help you free of charge with any question in minutesContact us