Search code examples
.htaccesshyperlinkhttp-referer

Block specific URL from hitting your site


All, I'm getting a lot of traffic to my website from back links and it's affecting my google analytics. Is there a way to block a specific website from accessing my website through .htaccess? For example purposes, if I want to block http://foo.com how would I do that? Is there a better way then .htaccess?

Thanks in advance!


Solution

  • Try adding the following to your .htaccess file

    #if the request came from foo.com
    RewriteCond %{HTTP_REFERER} ^http://foo\.com$
    #then serve it a 403 Forbidden
    RewriteRule . - [F,L]