Blocking Unwanted Referrers with .htaccess

This is something I've wanted to do for a while now, but I thought I couldn't on Nearly Free Speech. Turns out I could, after all.


Because Taylor Troesh had shared one of my posts to Hacker News, I decided it was time to get serious about rejecting traffic from sites like HN. I know it’s unreasonable, and even ‘childish’, but I don’t feel obligated to care. This is my website, which I operate at my own expense. I reserve the right to refuse service to anyone, at any time, for any reason.

I had previously been frustrated in my attempts to reject unwanted referrers on Nearly Free Speech. I had assumed that since NFS didn’t let people block IP ranges in .htaccess, they might not let them block user agents or referrers, either.

This was a mistaken assumption on my part. The problem was that I was using incorrect syntax in .htaccess. Emboldened by my success in blocking bots in .htacess, I decided to try blocking referers using a variation on the syntax that had worked for user agents.

Turns out the following syntax was what I needed.

# Got referred here by Hacker News
# or a shitty search engine, social platform, or forum?
# Computer says, ‘fuck you.’
RewriteCond %{HTTP_REFERER} news.ycombinator.com [NC,OR]
RewriteCond %{HTTP_REFERER} google.com [NC,OR]
RewriteCond %{HTTP_REFERER} bing.com [NC,OR]
RewriteCond %{HTTP_REFERER} twitter.com [NC,OR]
RewriteCond %{HTTP_REFERER} facebook.com [NC,OR]
RewriteCond %{HTTP_REFERER} threads.net [NC,OR]
RewriteCond %{HTTP_REFERER} instagram.com [NC,OR]
RewriteCond %{HTTP_REFERER} bsky.app [NC,OR]
RewriteCond %{HTTP_REFERER} x.com [NC,OR]
RewriteCond %{HTTP_REFERER} reddit.com [NC,OR]
RewriteCond %{HTTP_REFERER} forum.agoraroad.com [NC,OR]
RewriteCond %{HTTP_REFERER} kiwifarms.net [NC]
RewriteRule .* - [F]
blocking unwanted referrers in .htaccess

Of course, HN’s management or that of other sites can make my efforts irrelevant by spoofing the referrer or applying rel="noreferer" to any links to my website that get posted on theirs. They’ve done it to the Asahi Linux website. They can do it to me. That’s their prerogative.

However, it is no less my prerogative to screen out certain referrers on my website should they send me that information. What you give me is mine to use as I please.

Besides, the aggrieved entitlement we see from some HN users when reminded that they are not universally welcomed is cheap, reliable entertainment. The way they react to being (temporarily) thwarted, as a mere referrer redirect was an insurmountable obstacle, makes thwarting them worthwhile. They have nobody to blame but themselves if they’re going to tell me where they’re coming from.

But if they want to think I’m being unreasaonble or childish because I refuse traffic from HN, that’s not my problem. I am not interested in being read by College Republicans who majored in computer science. Sing it loud for the the people in the back: My site? My rules!

And to all who object, listen to this song and take the lyrics to heart.

Lord of the Lost: “Leave Your Hate in the Comments”
Lord of the Lost: “Leave Your Hate in the Comments”