Forum Moderators: phranque

Message Too Old, No Replies

Redirect Based Upon Search Phrase

         

JustAnotherPerson

11:58 am on Nov 23, 2007 (gmt 0)

10+ Year Member



I've been looking all over to information on how to automatically redirect site visitors to specific pages based upon the search phrase they use to find the site. For example, if a user does a Google Search for the phrase "dog bones" I would like them to be automatically redirected to a page on the site pertaining to "dog bones." I know it's possible but I can't remember how. Any ideas? Thanks.

vincevincevince

12:05 pm on Nov 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can do that using both .htaccess's mod_rewrite function (redirect according to?q= in the REFERER to a search page) or via PHP or similar which reads HTTP_REFERER from the server variables; both are essentially the same.

The main worry however is that your method will be picked up by search engines and your site penalised because you are sending pages to Google which you don't let visitors see. e.g. a visitor for 'dog bones' will be sent directly to the right page anyway, and if he's not then you should solve the problem by improving your SEO for the right page so that he is next time.

JustAnotherPerson

9:45 pm on Nov 23, 2007 (gmt 0)

10+ Year Member



Thanks for your help. I've got a couple of questions -

1. Can you provide me with an example of how to do this using either .htaccess or php?

2. I only want to redirect using a couple of search phrases, (i.e., "dog bones" and "cat food"). Will such limited us also penalize my site by Google?

Thanks.

rocknbil

9:58 pm on Nov 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



EDIT: Actually this idea is wrong, it doesn't specifically target the query string, sorry. But it may help you get rid of query string URL's.

====================================

Put a space before!, this board removes them.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ /path_to/your_search_script [L]

"your_search_script" will be responsible for correctly directing the request to the appropriate output. So if the product contains "dog bones" in the title, all you really need to to is look it up and populate "my_product_id" with the product id used by your system and continue with output.

You won't be penalized so long as the visitor gets the same output as the search engine.

JustAnotherPerson

10:04 pm on Nov 23, 2007 (gmt 0)

10+ Year Member



Thanks for the response. I'm afraid, however, that I do need to create a redirect based specifically upon a very limited number of search phrases obtained from search engines.

Thanks for the information though.

JustAnotherPerson

4:35 am on Nov 26, 2007 (gmt 0)

10+ Year Member



Hi All,

Could anyone tell me the exact code I need to use to accomplish this?

Thanks.