Redirecting Hacker News traffic away from your site via Nginx configuration
⚠️
This post was automatically migrated from my old blogging software, and I have not reviewed it for problems yet. Please contact me if you notice any important issues.
If you wish to redirect traffic from Hacker News away from your site for some reason, placing these nginx configuration directives in your site’s server {
block will do this trick. This won’t work inside a location
block, at least in my experience.
This snippet was last updated December 13, 2021.
if ($http_referer ~* (news.ycombinator.com)) {
return 302 https://news.ycombinator.com;
}
if ($http_referer ~* (hckrnews.com)) {
return 302 https://hckrnews.com;
}
if ($http_user_agent ~* "^HackerNews/") {
return 302 https://news.ycombinator.com;
}
if ($http_referer ~* (hn.premii.com)) {
return 302 http://hn.premii.com;
}
if ($http_referer ~* (hackerweb.app)) {
return 302 https://hackerweb.app;
}
if ($http_referer ~* (hn.algolia.com)) {
return 302 https://hn.algolia.com;
}