网站被恶意镜像解决方法

in #wordpress7 years ago (edited)

真心搞不懂,我这一个破博客居然会有人镜像,真是吃饱了撑啊!刚开始发现 Google 搜索博客会出现一下稀奇古怪的结果,没多在意,也不知道是怎么回事。后来知道那是被镜像了,然后 Google 找到了解决办法,折腾上去几天,好像真有点效果。

参考

1、张戈博客 - 分享一个网站防镜像以及解决七牛静态页面跳转的js方案

2、龙笑天下 - 网站被恶意镜像怎么办 一段代码轻松搞定(全面版)

在用代码

1、.htaccess 阻止 IP(龙笑天下)

这个方法简单粗暴,但是镜像站换了 IP 就失效了。我主要用来对付这货:https://fireproxy.crushus.com/cyhour.com,实测上面参考的代码除了阻止 IP 外,对这个站都无效。

a.获取镜像服务器 IP。

注:这个 IP 不是 ping 到他域名的 IP!!!

复制如下代码,新建一个 php 文件,并命名为“ip.php”上传到你的网站根目录。

<?php
    $file = "ip.txt"; //保存的文件名
    $ip = $_SERVER['REMOTE_ADDR'];
    $handle = fopen($file, 'a');
    fwrite($handle, "IP Address:");
    fwrite($handle, "$ip");
    fwrite($handle, "\n");
    fclose($handle);
?>

然后访问你网站的镜像站点,在地址后面加 /ip.php,在你的网站根目录就能找到 ip.txt 文件,复制里面的 IP 地址。

b.打开 .htaccess 文件,在后面加上如下代码(xxx.xxx.xxx.xxx 修改为上面获得的 IP)

Order Deny,Allow
Deny from xxx.xxx.xxx.xxx

如果你使用 CDN,可以直接在 CDN 后台添加 IP 黑名单。这个时候你再刷新一下镜像站点,如无意外,已经 403 了。


2、WordPress 专用版(龙笑天下)

add_action('wp_footer','theme_kimsom_reverse_proxy_defense', 99);
function theme_kimsom_reverse_proxy_defense(){
    $currentDomain = '"cyhour" + ".com"';
    echo '<lt;img style="display:none" id="inlojv-rpd" src="nothing" data-url="'.home_url().'" onerror=\'var str0=document.getElementById("inlojv-rpd").attributes.getNamedItem("data-url").nodeValue;var ishttps="https:"==document.location.protocol?true:false;if(ishttps){var str1="https"+"://";}else{var str1="http"+"://";}var str2='.$currentDomain.';var str3=str1+str2;if( str0!=str3 ){location.href = location.href.replace(document.location.host,'. $currentDomain .');}\'/>';
}

3、禁止 UA 为空或含有 PHP 的请求(张戈博客)

if(!is_admin()) {
    add_action('init', 'deny_mirrored_request', 0);
}
function deny_mirrored_request()
{
    $ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
    if( ( empty( $ua ) ) || preg_match('/PHP/i', $ua)) {
        header("Content-type: text/html; charset=utf-8");
        wp_die('请勿采集本站,因为采集的站长木有小JJ!');
    }
}

福利

http 跳转 https 的 js 代码(张戈博客)

<script type="text/javascript">
/* 如果当前是http访问,那么跳转到对于的https页面 */
if (document.location.protocol != "https:") { 
    location.href = location.href.replace(/^http:/,"https:");
} 
</script&gt>

完。

via:常阳时光 - https://cyhour.com/510/

Sort:  

在博客里多加几个到自己地址的链接,难道怕别人镜像?镜像越多越好

为啥镜像越多越好呢?

镜像多会有更多的人读到你的文章。如果他们把你的链接也copy过去不久能找到你这个原作者了吗

你说的不是镜像,是转载之类的,镜像的话文章链接全都会改成镜像站链接的。比如 B 是 A
的镜像站,那么 B 和 A 内容和名称是一模一样的,但是,B 站链接是 B 站的,不会有 A 站相关链接。

Coin Marketplace

STEEM 0.16
TRX 0.15
JST 0.027
BTC 60244.17
ETH 2333.72
USDT 1.00
SBD 2.47