简体   繁体   English

仅允许在 .htaccess 中的特定时间从特定引用者访问

[英]Allow access from specific referer only on a specific time in .htaccess

I am using this code in my htaccess file to block traffic from specific websites to my website and it works:我在我的 htaccess 文件中使用此代码来阻止从特定网站到我的网站的流量,它可以工作:

RewriteEngine On
SetEnvIfNoCase Referer "example.com" bad_referer
Order Allow,Deny
Allow from ALL
Deny from env=bad_referer

Now what I want is set a time for this code, for example, visitors from a specific website are only allowed to visit my website from 08:00 till 17:00现在我想要的是为这段代码设置一个时间,例如,来自特定网站的访问者只能在 08:00 到 17:00 之间访问我的网站

I tried this:我试过这个:

RewriteEngine On
RewriteCond %{TIME_HOUR}%{TIME_MIN} >0800
RewriteCond %{TIME_HOUR}%{TIME_MIN} <1700 
SetEnvIfNoCase Referer " example.com " bad_referer
Order Allow,Deny
Allow from ALL
Deny from env=bad_referer

But does not seem to work, visitors are still blocked between the set time stamp但似乎不起作用,访客仍然在设置的时间戳之间被阻止

Thanks谢谢

Robert罗伯特

You can't use SetEnv with RewriteRule as these two directives are part of two different apache modules.您不能将SetEnvRewriteRule一起使用,因为这两个指令是两个不同 apache 模块的一部分。 You can use mod-rewrite to achieve what you want to:您可以使用mod-rewrite来实现您想要的:

RewriteEngine On
RewriteCond %{TIME_HOUR}%{TIME_MIN} >=0800
RewriteCond %{TIME_HOUR}%{TIME_MIN} <=1700
RewriteCond %{HTTP_REFERER} example\.com [NC]
RewriteRule ^ - [R=403,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM