Mobile app version of vmapp.org
Login or Join
Alves908

: How do you block a referer but for a specific URL using .htaccess? I would like to block a referral URL from a specific domain using .htaccess. The link itself must still function on its

@Alves908

Posted in: #Htaccess #ModRewrite

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: example.com/page.html
Referral site link: forums.referer-site.com/thread1/ On the referring site URL there is a link to 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?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Alves908

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

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 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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme