Apache redirect based on referrer

apache-2.2mod-rewriteredirect

I've just noticed that schoolmate.r09.railsrumble.com seems to be doing a rewrite to one of my domains, agilegrad.com. This is kind of annoying since that site is the top hit on google when searching for my domain and the address bar stays as schoolmate.r09.railsrumble.com when following the link.

I'd like to redirect incoming requests with schoolmate.r09.railsrumble.com in the referrer variable to agilegrad.com, but the following in my vhost config for agilegrad.com isn't working for me:

RewriteEngine on
RewriteCond %{HTTP_REFERER} railsrumble
RewriteRule ^/(.*) http://www.agilegrad.com/$1 [L,R=301]

With this on, I see a bunch of redirects in my access log, but only for static files (cs, javascript). This is the first time I've tried using mod_rewrite, so I'm not even sure if I can accomplish what I want, which is to do a full redirect to my domain and have it appear to the user that they are at agilegrad.com.

Best Answer

This isn't caused by any rewrite rules on railsrumble.com. Your website is the default website for the IP address (http://74.207.240.229), both sites are served from the same IP address.

You can forward all visitors who are not using your own domain with the following rewrite rules:

RewriteEngine On
RewriteCond %{HTTP_HOST} !.*?agilegrad.com$ [NC]
ReWriteRule /(.*)$ http://www.agilegrad.com/$1 [R=301,L]
Related Topic