Guides and tutorials

Hundreds of tutorials and step by step guides carefully written by our support team.

Block web access using .htaccess

In this manual we will explain how to deny someone access to our website by editing the .htaccess file.

Connect via FTP to the directory "/datos/web/" and edit the file ".htaccess".

⚠️ The ".htaccess" file is hidden. If you don't see it, you should activate the option to see hidden files in your FTP client. There is also the possibility that you will have to create it. ⚠️

Next, add the lines of code that we specify according to the needs of your web page.

Deny access to a specific IP

With this first code, you can block access to a user by their specific IP address. In this way, when the user wants to connect, a 403 Forbidden error will be shown:

deny from 173.236.241.100

You may need to block an entire block of IP (we don't recommend it). To do this you must leave the last octet unspecified, in this way you deny access to anyone who has that IP in the range of 173.236.241.0 to 173.236.241.255:

deny from 173.236.241.

Allow access only to a specific IP

If, on the other hand, what you need is that nobody can access your website, but you or someone must be able to see it to work on it, you can block access to all IPs except one in particular with the following code:

order deny,allow
deny from all
allow from <TU_DIRECCION_IP>

Deny access to a specific domain

With this we will make that anyone who connects to your site from a specific domain, for example "www.swmanuales.com", cannot access. There are three ways to do it:

403 forbidden

If someone clicks a link on swmanuales.com that redirects to your site, they will see a 403 Forbidden error:

SetEnvIfNoCase Referer "swmanuales.com" bad_referer
Order Allow,Deny
Allow from ALL
Deny from env=bad_referer

500 internal server error

A 500 Internal Server Error will be displayed to deny any web request that is redirected from the domain swmanuales.com:

RewriteEngine on
RewriteCond %{HTTP_REFERER} swmanuales\.com [NC,OR]
RewriteRule .* - [F]

Redirection to google.com

This code redirects any visitor from the URL http://swmanuales.com hacia la URL http://www.google.com:

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://swmanuales.com/
RewriteRule /* http://www.google.com [R,L]

Deny file access

With this code we are going to deny access to any file with the extension that we indicate. Instead of displaying the content, you will see a 404 error. In the example, the code forces any file ending in .inc to give the 403 error when visited:

<Files ~ "\.inc$"> 
Order Allow,Deny
Deny from All
</Files>

Negar acceso a archivos "escondidos"

Deny access to "hidden" files Hidden files, such as .htaccess, are those that begin with a period ".". These types of files are not visible to visitors. You can recursively deny all access to all files by putting the following code at the top of your .htaccess:

RedirectMatch 403 /\..*$

Deny access to directories

If you don't have an index file in your directory, all your files are listed in a directory list for anyone to see. Usually we always have an "index.html o index.php" file in our service, but we may need to deny access for security reasons. You can deny access to a specific folder or directory with the following code so that when a visitor accesses the list of directories it will give a 404 Forbidden error:

Options -Indexes

Deny access to a specific directory

If you have a specific directory that you don't want users to access, you should use the following code. We will put for example that the directory that we want to block is called "swmanuales":

RewriteEngine On
RewriteRule (^|/)swmanuales(/|$) - [F]

Deny access during a specific time in the day

In this way we will deny access to our website during a specific time of the day. We can specify one or several hours.

Example specifying that access is not allowed from 15:00 to 15:59:

RewriteEngine On
# Si la hora es 15 (3 PM)
RewriteCond %{TIME_HOUR} ^15$
# Negar todos los accesos
RewriteRule ^.*$ - [F,L]

Example specifying that access is not allowed from 15:00 to 16:59 and from 6:00 to 7:00:

RewriteEngine On
# Si la hora es 3 PM o 4 PM o 6 AM
RewriteCond %{TIME_HOUR} ^15|16|06$
# Negar todos los accesos
RewriteRule ^.*$ - [F,L]
More than 2000 m² of own facilities and Data Centers in Spain
Your privacy is important for us
We use our own cookies for the proper functioning of the site. In addition, third-party cookies are used for analytical purposes only. This information is not associated with any person so that personal identifying data is not stored, but is only information that is collected to identify the session, with the aim of facilitating the analysis of the website. You can change your preferences at any time by entering this website again. For more information about our cookie policy you can visit our Cookies. You can press the "Accept and close" button to give us your consent or you can access more detailed information and manage cookies.
More than 2000 m² of own facilities and Data Centers in Spain
Your privacy is important for us
We use our own cookies for the proper functioning of the site. In addition, third-party cookies are used for analytical purposes only. This information is not associated with any person so that personal identifying data is not stored, but is only information that is collected to identify the session, with the aim of facilitating the analysis of the website. You can change your preferences at any time by entering this website again. For more information about our cookie policy you can visit our Cookies. You can press the "Accept and close" button to give us your consent or you can access more detailed information and manage cookies.