Search code examples
apache.htaccessmod-rewritehttp-redirecthttp-status-code-301

Rewrite Apache directive for a 301 redirect


There is a malicious site which has replaced mine in Google search results. I checked the headers and this malicious domain is sending traffic directly to our servers.

I'd like to rewrite Apache's directives so that there is a 301 redirecting any traffic from the malicious site to our site in order to get Google to give me back my listing.

Does anyone know how to write this directive? I hardly know anything about this stuff but I think it involves RewriteEngine. Do I update it in .htaccess?

UPDATE FOR CLARITY: When someone searches for my company name in Google the malicious domain is the top result. Click on it and it immediately goes directly to our server - it's not a redirect, it's a straight 200 to my IP (but in their domain). Makes me think they're pointing their DNS to my IP. Is there a way to write a directive that would execute a 301 redirect to my domain whenever traffic was coming from the malicious domain?

RESOLVED: I had help figuring this out... here's the fix. I put this at the top of my {site.com}.conf file:

<VirtualHost *:80>
      RedirectMatch permanent ^/(.*) http://www.{site}.com/$1
</VirtualHost>

Solution

  • I had help figuring this out... here's the fix. I put this at the top of my {site.com}.conf file:

    <VirtualHost *:80>
       RedirectMatch permanent ^/(.*) http://www.{site}.com/$1
    </VirtualHost>