There is a problem with a 'page not found' error showing when implementing a 'Two page' Google Custom Search on a Drupal site. Using the 'Two page' approach you can have a seperate search box and results page.
Following the Google Search setup instructions results in you being diverted to a URL matching the search keywords, rather than the search results page URL. For instance, if searching for 'sunflower' you'll be directed to 'www.yoursite.com/sunflower'.
The problem lies in the fact that both Google Search and Drupal use 'q' in their query string. There is a module for Google Custom Search, but this isn't maintained and doesn't support the 'Two page' approach.
Here is the way to get around it when adding the scripts to your Drupal site. Just make sure you select the 2 page layout when setting up the 'look and feel' on the Google Custom Search pages.
1) Add the Google search script to your site <head>
Add the below script before your closing </head> tag. The script will be something like the below, with the following customisations:
- Replace the var cx value with your own unique Google Search Engine ID. Obtained when setting up the search in Google Custom Search Engine pages.
2) Add the search box
Add this to the area where you want to render your search box - probably in a block. You will need to add this using PHP text format.
- Add your search result destination page results_Url so that it points to your own search results page URL.
- Notice the additon of queryParameterName="as_q" - this is the bit which stops the conflict with Drupals default 'q' query string.
<gcse:searchbox-only resultsUrl="http://www.mysite.com/search-results" queryParameterName="as_q"></gcse:searchbox-only>
3) Add the search results
Add this to the region where you want to render out your search results, probaby the content region of a search results page you've created (again using PHP text format).
The URL of the page you put this on will be specified when setting up your Google Custom Search settings within Google Webmaster Tools.
Notice the additon of queryParameterName="as_q" - which as mentioned above stops the conflict with Drupals default 'q' query string.
<gcse:searchresults-only queryParameterName="as_q" linkTarget="_self"></gcse:searchresults-only>