I would like to block a referral URL from a specific domain using .htaccess.

The link itself must still function on its own, it is only when the incoming referrer matches.

My Site Link: www.example.com/page.html

Referral site link: http://forums.referer-site.com/thread1/
On the referring site URL there is a link to www.example.com/page.html.

Note: There are other valid links from the forums.referer-site.com so this is why I do not want to block all links from that site.

Is it possible to block the referral link using .htaccess? if so what is the correct expression?

  • Pretty sure you can;t do this via htaccess as it is the browser's prerogative to send the referrer value
    – John Conde
    Commented Feb 26, 2016 at 12:35
  • 2
    Most browsers will send the referrer header. It should be possible to put a block in place that will apply only for visitors from a specific external page to one of your pages that will be 90% effective. Commented Feb 26, 2016 at 13:26

1 Answer 1


Try the following in the .htaccess file in the root of your site.

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://forums\.referer-site\.com/thread1/ [NC]
RewriteRule ^page\.html - [F]

This will send a 403 Forbidden when someone follows a link to your /page.html URL from the referring site.

There is always the risk that browsers won't send an HTTP referer if the user has disabled this, but it should work in most cases.

Note that this is from a referring URL that starts http://forums.referer-site.com/thread1/ (in case the exact URL can change due to pagination). Put a $ on the end of the CondPattern for an exact match.

EDIT: If you have existing directives in your .htaccess file, then this should probably go near the top, after the existing RewriteEngine directive and, importantly, before any rewrite/routing directives.

  • Okay I will try your edit later, I didnt have much luck this morning but was in a rush. I will report back. Thanks for the reply!
    – sr_1436048
    Commented Feb 26, 2016 at 19:26
  • @sr_1436048 You haven't reported back in a while now ;-) Did the solution work for you?
    – Oliver
    Commented Oct 6, 2017 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.