2014-07-07 32 views
1

我希望阻止外部网站访问我网站上的文件的子目录。我编写了一个规则,并使用http://htaccess.madewithlove.be/进行了测试,但即使它在测试中与外部引用参数匹配,但无法在我的网站上运行。Apache htaccess重写规则拒绝外部网站访问子目录

从Google到私人文件的具体链接仍然有效,并且不会像我期待的那样重定向到我的网站主页。我已经检查了HTTP标头,并且Google推荐人按预期呈现。

RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^$ 
RewriteCond %{HTTP_REFERER} !test.example.com [NC] 
RewriteRule ^(.*)my_sub_directory(.*)$ https://test.example.com/? [R] 

回答

0

将这个规则在/my_sub_directory/.htaccess

RewriteEngine on 

RewriteCond %{HTTP_REFERER} !^$ 
RewriteCond %{HTTP_REFERER} !=test.example.com [NC] 
RewriteRule^https://test.example.com/? [R,L]