Blocking Referrer Spams For Good

April 09, 2015/POSTED BY Marjan Nikolovski/0 Comments
We are using Azure Websites to host a WordPress instance for our company website. We’ve built a habit to do some analyses on the analytic data that we are gathering from our visitors. Before start analyzing first we clear out the noise from the data(spammers, search engines, non existing referrers).

As the site is becoming more popular due to our tech blog we’ve noticed increasing traffic from referrer spams. Know what? We’ve got bored.

Lets patch…

Navigate to Azure Management Portal. Select your website and click on WebMatrix. webmatrix

Open your web.config and add url rewrite rules to block referrer spams that you’ve noticed in your analytic account.

<configuration>
  <system.webServer>
	<!-- REWRITE RULE FOR BLOCKING REQUEST BY HTTP REFERER -->
    <rewrite>
       <rules>
          <rule name="abort referrer spam" stopProcessing="true">
            <match url=".*" />
            <conditions>
              <add input="{HTTP_REFERER}" pattern="(semalt\.com)|(buttons\-for\-website\.com)|(best\-seo\-solution\.com)|(darodar\.com)|(itolist\.eu)|(s\.click\.aliexpress\.com)|(humanorightswatch\.org)|(hulfingtonpost\.com)" />
            </conditions>
            <action type="AbortRequest" />
          </rule>
       </rules>
    </rewrite>
	<!-- PREVENT CLICKJACKING  -->
    <httpProtocol>
      <customHeaders>
        <add name="X-FRAME-OPTIONS" value="SAMEORIGIN" />
		<add name="Access-Control-Allow-Origin" value="http://www.emitknowledge.com" />
		<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE" />
		<add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
		<add name="Access-Control-Max-Age" value="1728000" />
      </customHeaders>
    </httpProtocol>	
  </system.webServer>
  <system.web>
    <customErrors mode="On" />
  </system.web>  
</configuration>


Activate Fiddler to ensure that the rules are active and will be blocking the requests.

fiddler

Happy hacking!

About Marjan Nikolovski

Co-owner, Team lead Full stack .NET and Javascript engineer, speaker and active open source contributor. Excited about Distributed programming, Software architecture, Cloud based solutions.

0 Comments

Leave a comment

Your email address will not be published. Please mark all required fields.

Your Name (required)

Your E-Mail (required)

Subject (required)

Comment