(as)  [sysadmin] [blog]

User Tools

Site Tools


choose.php - ChooSE your search engine

choose.php is a PHP script intended to let users choose their favorite search engine. Instead of providing a link to a particular web search one can point to an installation of choose.php which allows users to choose a preferred search engine before doing the actual search.

The script is meant to be used for instance in blog posts and comments 1) or in electronic mail communication (for this purpose the script produces a link to itself to be copied into the message).

The basic idea is that people should have a free and easy to use choice of search engines.

ChooSE @wox.at


  • Freedom of choice ;-)
  • Extended listing of search engines: Shown with ?ext added to URL (example showing extended list)
  • Preselect a search engine: A default search engine is set up by the script itself. It can be overruled by adding ?e= + the key for the search engine (example for Startpage).2)
  • Search engines can be easily added or changed by editing the script.
  • Access keys for search engines: E.g. Alt-Shift-g for Google, Alt-Shift-b for Bing, …
  • Access keys for search string field (Alt-Shift-f) and Submit (Alt-Shift-s)

Instructions for use

Feel free to use my own installation of choose.php at https://wox.at/s/. However, I recommend that people set up their own search engine switcher (for added freedom of choice and privacy).

Basically, choose.php comes as a single PHP file. Download it (see links below), rename appropriately, set permissions if needed, and edit the file to change a few settings. That's it.

Important settings to make it work are values of $me, $mesuffix, and $c_action. Let's assume you have a blog at http://blog.rats.at. You copied choose.php to the main directory, so it should be available at http://blog.rats.at/choose.php. Then set


URL rewriting

For https://wox.at/s, I use URL rewriting (on an Apache server) to remove the filename from the URL. I copied choose.php as index.php into the folder /s. My .htaccess contains

RewriteEngine   on
RewriteBase /s
RewriteRule ^$                        index.php  [L]
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule (.*)                      index.php?q=$1  [QSA,L]

With these rewriting rules I can set in index.php (i.e. choose.php)


Dealing with slashes

If you use the rewriting rules as shown above you'll probably observe that when searching for a string with 2 or more slashes (//) the Apache server will reduce the slashes to single slashes3).

A solution is to use RewriteCond %{THE_REQUEST} and %1 as in

RewriteEngine   on
RewriteBase /s
RewriteRule ^$                        index.php  [L]
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteCond %{THE_REQUEST}            ^GET\ /s/([^\s]+)
RewriteRule .                         index.php?q=%1  [QSA,L]

Speaking of slashes, in rare cases they are encoded as %2F instead of %252F. Apache by default does not accept %2F and returns a 404. One could probably write a RewriteRule for this, but another approach is to turn AllowEncodedSlashes on. However, this needs to be done in the server configuration:

# Needed for ChooSE but should not hurt otherwise either
AllowEncodedSlashes On

Processing ? and & parameters

Eventually, we also want to pass ?ext and possibly other parameters to the script. For this we need another rule which needs to be inserted right after RewriteRule ^$ index.php [L]:

RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteCond %{THE_REQUEST}            ^GET\ /s/(.*)\?(.*)\ HTTP/
RewriteRule .                         index.php?q=%1&%2  [QSA,L]

Download & source

  • Download current version4): choose.php.txt (~ 14 KB; rename to e.g. choose.php)
    • Example CSS choose.css (~ 1 KB; should give reasonable results out of the box)
    • Example XML for search engine addon5): opensearch.xml (~ 1 KB; needs to be adapted, of course)
  • View source (with syntax highlighting)
Example usage in a comment: "Have you tried to look it up? Most search engines provide good results, see https://wox.at/s/choose.php?q=what+does+RTFM+mean"
One user wanted to use my installation of choose.php as home page for the browser but wanted to be able to pre-select her own favorite search engine. Links for this setup as home page are provided as anchors behind the access keys as shown in the extended listing.
Version history is included in main file.
choose_php.txt · Last modified: 2020-12-12 20:41 by andreas

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki