Chris Dzombak

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.

    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;
    }