Add a Custom Search Engine to Safari - by Wesley Moore

Add a Custom Search Engine to Safari

Published on

In my ongoing efforts to distance myself from Google I started using DuckDuckGo as my default search engine. I tried the DDG Safari extension but didn’t really like it, especially since it needed to add an entire new toolbar to the browser. Other suggestions for adding DDG to Safari involved hacking the binary or other extensions, which I wasn’t interested in.

Update 2018: Safari and most other browsers now support DuckDuckGo in their default search engine list. 🎉

Update 2012: There an easier way to achive what I describe below: Just add a hosts file entry for that points at DuckDuckGo’s IP address and set you search engine to Yahoo! in Safari. See DuckDuckGo for the full instructions.

My solution to the problem was to hijack the Bing option in the default search box for use with DDG. Note: This solution assumes you will never want to go to the domain, not a problem for me. The steps to implement it are:

Add an entry for to /etc/hosts that points the domain to your local machine:

Next configure an Apache virtual machine to respond to the domain and redirect the request to Duck Duck Go (or your search engine of choice). This works because DDG accepts the search query in the same query string parameter, q, as Bing and ignores the other Bing related params.


<VirtualHost *:80>
    RewriteEngine On
    RewriteRule ^/search(.*)$$1 [redirect,last]

For this to work you will need to have “Web Sharing” enabled in the Sharing preferences pane and have the the following line included in /etc/apache2/httpd.conf:

Include /private/etc/apache2/extra/httpd-vhosts.conf

Restart Apache (sudo apachectl graceful) and set your search engine to Bing in Safari. Do a search and you should end up at the DDG results. One of the neat features of DDG is its !bang syntax, which allows you to search to 100s of sites directly. One of which is !g for those times when you need to fall back on Google.

Comment icon Stay in touch!

Follow me on Twitter or Mastodon, subscribe to the feed, or send me an email.