.htaccess maker

.htaccess generator maker easier

Htaccess Block or deny visitors by referrer

Sometime you want to stop traffic that coming from some sites, so you need to block or deny visitors by using their referrer, the best solution is to use htaccess, Apache Web Server enables us to do that in a simple way.

The following code will block any visitor by referrer:

RewriteEngine on
Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} domain_name\.com [NC]
RewriteRule .* - [F]

Make sure that the mod_rewrite is enabled in your Apache server, we use RewriteCond to setup the condition for the redirect that will be made, RewriteRule is to set the target of the redirect, the sentence Options +FollowSymlinks is to prevent the server from displaying Error 500: Internal Server Error in some cases, the above code is to stop traffic from one domain, if you decided to prevent more than one domain, the code will be as the following:

RewriteEngine on
Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} first_domain\.com [NC,OR]
RewriteCond %{HTTP_REFERER} second_domain\.com
RewriteRule .* - [F]

Note: be aware of editing your Htaccess file, any error in writing my cause Error 500, which will stop your site.

Your .htaccess File

Download Copy

You can create the .htaccess file using a good text editor like TextPad, UltraEdit and Microsoft WordPad. You cannot use Microsoft NotePad. An .htaccess file can contain a single or multiple lines depending upon the functions you want to include in it. You will need to use an FTP (File Transfer Protocol) program to upload the file. Also you must to upload the file in “ASCII” mode. Some FTP programs use “BINARY” as the default to upload files. If that’s the case you must change it to “ASCII”. Upload the file to the directory you want it to reside in. when you look at the files in your website’s directory you might not see it as your web server’s software is probably hiding it.

Block visitors by referrer

separated by comma or new line

Copyright © 2021 · htaccessmaker.com · Log in