To prevent unwanted website visitors, for example sources of spam, visitors can be blocked by IP address or by the resolved website URL. A few extra lines in the .htaccess file is all that’s required.
The same can be achieved by editing the appropriate Apache configuration files. However, if you are hosting your website on someone else’s server with shared hosting this won’t be available to you. Instead the same access control is implemented through the .htaccess file.
Below is an example of the .htaccess file as taken from a WordPress website.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
The additional code to block certain visitors relates to the Apache Allow and Deny access directives. To catch the whole domain a dot is added to the start.
#Add exclusions Order Allow,Deny Allow from all Deny from .163.data.com.cn
The first line advises Apache in which order to apply the two directives. In this case Allow is applied first. The second line configures Apache to allow access from all visitors. And the final line is an example of blocking visitors from a particular domain name.
This code is then added above the existing within the file.
# BEGIN WordPress#Add exclusions
Order Allow,Deny
Allow from all
Deny from .163.data.com.cn<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Within the file the lines starting with a # are comments.


