So if anyone reading this is an htaccess expert and can give a me a little help I’d appreciate it. I’m looking to trap for queries for a specific term from a search engine for a specific page and redirect them elsewhere. For example:
if the query was
http://www.google.com/search?q=foo*
and it went to
http://www.wolf-howl.com/foo/
I’d like to redirect to
http://example.com/foo/
for people who come to the page any other way I’d still like to show them
http://www.wolf-howl.com/foo/
Related posts:
- How to Turn Off Personalized Search in Google Chrome With the impending arrival of Google OS I’ve been spending...
- How to Add Search Shortcuts to Google Chrome. Last week Danny Sullivan twittered he was looking for a...
- How TED Helped Me Understand Personalized Search Long time readers here will know that I’m not a...












{ 11 comments }
RewriteCond %{HTTP_REFERER} google.com [NC]
RewriteCond %{HTTP_REFERER} q=foo [NC]
RewriteCond %{REQUEST_URI} ^/foo/$
RewriteRule ^/foo/$ http://example.org/foo/ [R,L]
If the referer contains “google.com”
and the referer contains “q=foo”
and the request was for exactly “/foo/”
then redirect the user to “http://example.org/foo/”.
Untested and of course has to be tuned to work with different strings for foo. RewriteCond backreferences can be a good friend in this case.
What would be the point of doing a redirect depending on where they are coming from though? Woudln’t you rather have everyone go to the same page no matter how they got there?
That worked thanks Jan.
Johnathan, people coming from a SE are looking for a commercial result, others aren’t.
you should send all that chicken noodle soup traffic to a ringtones page
update you may need to change this line
RewriteCond %{HTTP_REFERER} q=foo [NC]
to this
RewriteCond %{HTTP_REFERER} ^q=foo^ [NC]
to catch it no matter what order the parameters are in
Would it make sense to check for q=foo before google.com, instead of putting every request from Google through to the second check?
> RewriteCond %{HTTP_REFERER} ^q=foo^ [NC]
Hmm I don’t get this change. I am definitely no htaccess expert, so i’m intrigued to try to understand this.
Doesn’t this tell mod_rewrite only to match if “q=foo” is found between the beginning and the beginning of the HTTP_REFERER string?
What about all the other SE’s?
The page doesn’t rank in the other SE’s because they do things the right way for this query instead of taking advantage of silly users habits to show more adverts
I was also wondering if “^q=foo^” works, or if you meant “*q=foo*”? Since ^ marks the start of the string and * would be a wildcard.
If you need to do any more fine tuning, the mod_rewrite cheat-sheet can come in handy for the basics:
http://www.ilovejackdaniels.com/mod_rewrite_cheat_sheet.png
Michael?
Comments on this entry are closed.