How to redirect WordPress search query to Google CSE?

How to redirect WordPress search query to Google CSE?

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).

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

One comment:

Leave a Reply

Your email address will not be published. Required fields are marked *