htaccess block keywords

larsjensen10

Newbie
Joined
Sep 24, 2008
Messages
28
Reaction score
0
How can I use htaccess to block users from entering my site if they have used certain keywords in search engines?
 
Larshensen,

While you can block people using .htaccess based on their IP address, I?m not sure how you would incorporate that with keywords. Alternatively, you could redirect them to a page where they couldn?t get access to your site using JavaScript and Google?s parameters from the URL in its index.

The code might look something like this to match the Google gi

if (document.referrer.match(/google\.com/gi) && document.referrer.match(/cd/gi)) {
var myString = document.referrer;
var r = myString.match(/cd=(.*?)&/);
var kw = myString.match(/q=(.*?)&/);
}

Then you could redirect them to another page on your domain with no navigation and saying something that would get them to avoid visiting your site. For example a page that says ?this site is down? or ?this site no longer exists? or whatever.

Hope that helps,

Shawn
 
This is one of the more advanced principles in cloaking/redirects; serving different and usually relevant content to a user based on who they are (search engine spider or user), geo-location, what searches they're doing, and where they clicked from...

...but it's FAR more complex than .htaccess statements. You'll need a complete redirect engine with lookups and database access. Check out Fantomaster Shadowmaker for an idea.

But the route can be quite Black-hat; depending on your configuration and network of sites. If its a single money-site, then anything like this has the potential for Google seeing varying/duplicate results; so tread carefully.
 
Last edited:
Kind of an interesting question...

Anyway, you can't. Google doesn't pass the keyword variable if the person is logged into their Google account (gmail, youtube, etc.). So you would only be able to get the keyword data from people who were not logged into Google or people who were using other search engines.

If you did want to redirect the 30-60% of people not logged into Google, I would use a PHP script that's called before the page loads. I'm sure there's a way to do it with .htaccess, but I only know the basics and I'm more advanced with PHP.
 
Back
Top