Search The Hostwinds Guides Knowledge Base

Block Visitors by URL Referrer Using htaccess

Share This Article [TheChamp-Sharing]

In some instances you may notice a surprising spike in traffic but no actual increase to files being requested or overall content being served. This may be an indication that someone is siphoning some of your content, such as images, and attempting to pass it off as their own or perhaps attempting to hack your website. In either case, you can block this type of behavior thanks to functionality provided by the Apache Web Server and utilizing an .htaccess file. If you have not created an .htaccess file or you’re not sure how to edit this file, please refer to the following guide which covers these topics in more detail: Creating and editing an .htaccess file

Block Referrer URL using htaccess

Please note that in order for this to work the mod_rewrite functionality will need to be enabled on the server that you’ll be doing this on. This functionality is enabled on Hostwinds Shared, Business and Reseller packages by default. If you’re not certain that this functionality is enabled on your server, you may refer to our guide which covers how to enable the mod_rewrite module: Enable Apache mod_rewrite module


To block a single referrer you’ll need to add the following code to an .htaccess file.


RewriteEngine on
RewriteCond %{HTTP_REFERER} [NC]
RewriteRule .* - [F]


The code above instructs the web server to not accept connections from the URL If you want to block multiple referrers, you can add additional rewrite conditions like so.


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


This code tells the web server to block requests/traffic originating from and domain to For both examples, specifying NC ensures that this block is not case sensitive. If you’d like to block additional referrers just ensure that you follow the format illustrated in the second example. Generally blocked referrers will receive a 403 error message upon trying to access any portion of your site that is covered by the .htaccess rules outlined in this article.