Search engine robots don't perform searches on your site directly (i.e., using search forms). In order for them to crawl and index search results, the search parameters would have to be contained within URLs, like:
example.com/search/index.php?keywords=fruits
example.com/search/index.php?keywords=apple
example.com/search/index.php?keywords=banana
Then robots can crawl these if found in the content of your site, your sitemap, or in external links pointing to your site. Otherwise, they won't be crawled so you don't have to be concerned with deciding what the best canonical URL would be.
If they are in that format and can be found however, search engines like Google will just decide which URL to display based on what they think is the best one, as indicated here:
When Google detects duplicate content, such as variations caused by
URL parameters, we group the duplicate URLs into one cluster and
select what we think is the "best" URL to represent the cluster in
search results. We then consolidate properties of the URLs in the
cluster, such as link popularity, to the representative URL.
Consolidating properties from duplicates into one representative URL
often provides users with more accurate search results.
You can also use the tool in Specify how Google should handle parameters, which includes options for:
- Let Googlebot decide. Googlebot will analyze your site to determine how best to handle the parameter. This is a good general option.
- Only URLs with value=x. Googlebot will crawl only those URLs where the value of this parameter matches this specified value.
- No URLs. Googlebot won't crawl any URLs containing this parameter.
The first option would just let Google choose how to index the search URLs, which is a good general option as indicated.
If you consider "fruits" to generally be a more relevant category to search engine users than a specific category like "apple", then you could use the second option to specify that Google crawl only a URL with the following search parameter:
example.com/search/index.php?keywords=fruits
Using the last option, you could tell Google not to crawl any URLs with search parameters, and instead simply have the main search page (example.com/search
) indexed so that search engine users would just see that page and perform their own searches.
In Summary - You can do any of the following:
- Let search engines select the best search results page/URL to index.
- Use the above tool to select just the more general "fruits" URL to index, or block the other search result pages in your robots.txt file or by adding a
noindex
meta tag to them.
- Exclude all the search result pages using the above tool, or by blocking them in your robots.txt or by adding a
noindex
meta tag to them.
- Block all search result pages and just have the main search page indexed alone.
The choice really depends on what you want to have indexed for your site.
example.com/search/fruits
toexample.com/search/index.php?keywords=fruits
then by definition the first page (search/fruits) does not exist and canonical should not point to a page that 301 redirects.example.com/search/fruits
because search engines may not properly interpret your query strings. Although generally they understand both, to increase your change that it works properly...