根据引荐来源禁用样式表

时间:2015-03-29 08:53:48

标签: php css .htaccess hotlinking

我不想让样式表(托管在我身上)加载到几个域上。

这就是我正在尝试的,但不起作用:

RewriteEngine on

RewriteCond %{HTTP_REFERER} ^http://example1.com/ [NC]
RewriteRule \.css$ http://www.mywebsite.com/dummy.css [R,L] 

RewriteCond %{HTTP_REFERER} ^http://example2.com/ [NC]
RewriteRule \.css$ http://www.mywebsite.com/dummy.css [R,L] 

我怎样才能让它发挥作用?

1 个答案:

答案 0 :(得分:0)

CSS /的的.htaccess

Options +FollowSymLinks
RewriteEngine On

# Redirect requests to load.php
RewriteCond %{REQUEST_URI} .*\.css$ [NC]
RewriteRule .* load.php

CSS /的 load.php

$referrer = $_SERVER['HTTP_REFERER']; 

if (strpos($referrer, 'allowedwebsite1.com') !== false or 
    strpos($referrer, 'allowedwebsite2.com') !== false ) {

    header("Content-type: text/css", true);
    $css = file_get_contents("style.css");
    echo $css;
} 
else {
    header("Content-type: text/css", true);
    echo ''; // empty stylesheet
}