Introduction
If you’re a content manager for a site, chances are one of your worst nightmares is having another site completely mirror your own, effectively “stealing” your site’s SEO. Site mirroring is the concept of showing the exact same content and styles as another site. And unfortunately, it’s super easy for someone to do.
How is it done?
Site mirroring can be accomplished by using a combination of “static hotlinking” and some simple PHP code. Here’s an example:
Original site:
Mirrored site:
The sites look (almost) exactly the same! The developer on the mirrored site used this code to mirror the content:
<?php //get site content $my_site = $_SERVER['HTTP_HOST']; $request_url = 'http://philipjewell.com' . $_SERVER['REQUEST_URI']; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request_url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $site_content = curl_exec($ch); //get the contents of the site from this server by curling it //get all the href links and replace them with our domain so they don't navigate away $site_content = preg_replace('/href=(\'|\")https?:\/\/(www\.)?philipjewell.com/', 'href=\1https://'.$my_site, $site_content); $site_content = preg_replace('/Philip Jewell Designs/', 'What A Jerk Designs', $site_content); echo $site_content; ?>
Unfortunately it’s super simple with just tiny bits of code to mirror a site. But, luckily there are some easy ways to protect your site against this kind of issue.
Prevent Site Mirroring
There are a few key steps you can take on your site to prevent site mirroring. In this section we’ll cover several prevention method options for both Nginx and Apache web servers.
Disable hotlinking
The first and most simple is to prevent static hotlinking. This essentially means preventing other domains from referencing static files (like images) from your site on their own. If you host your site with WP Engine, simply contact support via chat to have them disable this for you. If you host elsewhere, you can use the below examples to see how to disable static hotlinking in Nginx and Apache. Both links provide more context into what each set of rules does for further information.
Nginx (goes in your Nginx config file)
location ~* \.(gif|png|jpe?g)$ { expires 7d; add_header Pragma public; add_header Cache-Control "public, must-revalidate, proxy-revalidate"; # prevent hotlink valid_referers none blocked ~.google. ~.bing. ~.yahoo. server_names ~($host); if ($invalid_referer) { rewrite (.*) /static/images/hotlink-denied.jpg redirect; # drop the 'redirect' flag for redirect without URL change (internal rewrite) } } # stop hotlink loop location = /static/images/hotlink-denied.jpg { }
Apache (goes in .htaccess file)
RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC] RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC] RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?bing.com [NC] RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yahoo.com [NC] RewriteRule \.(jpg|jpeg|png|gif|svg)$ http://dropbox.com/hotlink-placeholder.jpg [NC,R,L]
Disable CORS/Strengthen HTTP access control
The above steps will help prevent others from linking to static files on your site. However, you’ll also want to either disable CORS (Cross Origin Resource Sharing), or strengthen your HTTP access control for your site.
CORS is the ability for other sites to reference links to your own site in their source code. By disabling this, you’re preventing other sites from displaying content hosted on your own site. You can be selective with CORS as well, to only allow references to your own CDN URL, or another one of your sites. Or you can disable it entirely if you prefer.
According to OWASP guidelines, CORS headers allowing everything (*) should only be present on files or pages available to the public. To restrict the sharing policy to only your site, try using these methods:
.htaccess (Apache):
Access-Control-Allow-Origin: http://www.example.com
This allows only www.example.com to access your site. You can also set this to be a wildcard value, like in this example.
Nginx config (Nginx):
add_header 'Access-Control-Allow-Origin' 'www\.example\.com';
This says to only allow requests from www.example.com. You can also be more specific with these rules, to only allow specific methods from specific domains.
Disable iframes
Another step you may want to take is disabling the ability for others to create iframes from your site. By using iframes, some users may believe content on an attacker’s site is legitimately from your site, and be misled into sharing personal information or downloading malware. Read more about X-Frame-Options on Mozilla’s developer page.
Use “SAMEORIGIN” if you wish to embed iframes on your own site, but don’t want any other sites to display content. And use “DENY” if you don’t use iframes on your own site, and don’t want anyone else to use iframes from your site.
Block IP addresses
Last, if you’ve discovered that another site is actively mirroring your own, you can also block the site’s IP address. This can be done with either Nginx or Apache. First, find the site’s IP address using the following:
dig +short baddomain.com
This will print out the IP address that the domain is resolving to. Make sure this is the IP address that shows in your site’s Nginx or Apache access logs for the mirrored site’s requests.
Next, put one of the following in place:
Apache (in .htaccess file):
Deny from 123.123.123.123
Nginx (in Nginx config):
deny 123.123.123.123;
File a DMCA Takedown Notice
Last, if someone is mirroring your site without your explicit approval or consent, you may also want to take action by filing a DMCA Takedown Notice. You can follow this DMCA guide for more information. The guide will walk you through finding the host of the domain mirroring your own site, and filing the notice with the proper group.
Thank you to Philip Jewell for collaborating on this article! And thanks for tuning in. If you have feedback, additional information about blocking mirrored sites drop a line in the comments or contact me.
Pirat says
Ive noticed that the content thieves either are hotlinkers and just steal my images or they re-upload them on their own servers and now its not hotlinking but content theft and I have to hire either a law firm or a dmca takedown agency in order to takedown the copyright infringing content.