Deny referrals from all domains except one

前端 未结 1 1033
南旧
南旧 2021-01-14 08:41

Is it possible to accept traffic from only one domain, ideally using a .htaccess file? I want my site to only be accessible via a link on another site I have.

I kno

相关标签:
1条回答
  • 2021-01-14 09:25

    Make that something like:

    RewriteCond %{HTTP_REFERER} .
    RewriteCond %{HTTP_REFERER} !yourdomain\.com [NC]
    RewriteCond %{HTTP_REFERER} !alloweddomain\.com [NC]
    RewriteRule .? - [F]
    

    The first RewriteCond checks that the referrer is not empty. The second checks that it doesn't contain the string yourdomain.com, and the third that it doesn't contain the string alloweddomain.com. If all of these checks pass, the RewriteRule triggers and denies the request.

    (Allowing empty referrers is generally a good idea, since browsers can generate them for various reasons, such as when:

    • the user has bookmarked the link,
    • the user entered the link manually into the address bar,
    • the user reloaded the page,
    • the browser is configured not to send cross-site referrer infromation, or
    • a proxy between your site and the browser strips away the referrer information.)
    0 讨论(0)
提交回复
热议问题