Redirecting Hacker News traffic away from your site via Nginx configuration
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;
}