How to redirect WordPress search query to Google CSE?

How to redirect WordPress search query to Google CSE?

asked Mar 6, 2015 by Eric Z Ma (41,910 points)

1 Answer

 
Best answer

You can configure Google CSE to read the query variable (by default, it is q).

Then, in your WordPress's .htaccess file, add these 2 lines

RewriteCond %{QUERY_STRING} ^s=(.*)$
RewriteRule ^ https://www.google.com/cse/publicurl?cx=xyz&q=%1 [R,L]

Here, "https://www.google.com/cse/publicurl?cx=xyz" is your CSE's public URL or the webpage that contains the Google CSE result (with Javascript provided by Google CSE in the page).

answered Mar 9, 2015 by Eric Z Ma (41,910 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...