I'm using Chrome as my default browser in Ubuntu 12.10. I need to use Firefox for business purposes (certain websites pertaining to my work only work with Firefox). Is there a way to force Ubuntu to use Firefox for certain types of URLs (maybe as defined by a regular expression) while maintaining Chrome as my default browser for all my other tasks? Perhaps as a shell script running in the background? I'd like this to work system-wide, covering links from Chrome itself as well as PDFs/ODTs, etc.

I have searched for solutions, but I couldn't find anything besides OpenWith, a Firefox extension which adds a button to open certain links in other browsers which would again require me to open Firefox beforehand, which does not help me at all.

Does anyone have any ideas? Something like Choosy for Linux?


The executable in Linux that opens a resource with your "favorite" program is called xdg-open. It is somewhat complicated, but you can add additional rules using xdg-mime install. However, I don't know if you can even do this for something like a specific URL.

This becomes further complicated in that specific desktop environments use different executables and methods for opening their default programs. For instance KDE has kde-open, but not every KDE application seems to use this.

Regardless, I got this partially working just using a shell script and a list of domains/URLs in a file. You can tweak it to your liking.

Note: You may need to repeat this process for other executables depending on your desktop environment. For example, Gnome has gvfs-open, KDE has kde-open, and XFCE has exo-open. (Even then, it might not work for every application.)

Note: The shell script is dependent on pcregrep being installed on your system.

  1. Find the xdg-open executable

    which xdg-open
  2. Create a new directory in your home folder

    mkdir -p ~/.local/bin
  3. Add the following to your ~/.bashrc file


    export PATH="${HOME}/.local/bin:${PATH}"
  4. Create the shell script in the newly created folder. (Be sure to edit the top four variables so they are correct for your system!)


    OTHER_BROWSER='/path/to/other-browser' # For instance /usr/bin/firefox
    BROWSER_OPTIONS='' # Optional, for command line options passed to browser
    if echo "$1" | pcregrep -q '^https?://'; then
        while read domain; do
            if echo "$1" | pcregrep -q "^https?://${domain}"; then
        done < "$DOMAIN_LIST_FILE"
        if [[ $matching -eq 1 ]]; then
            exit 0
    "$XDG_OPEN" ${*}
  5. Create the list of domains in your home folder


  6. Log out and log back in to have the settings take effect

| improve this answer | |
  • 1
    change pcregrep -q '^https?://' to grep -q '^http\?:\/\/' if you don't have pcregrep (whatever that is :) ) – Boris Churzin Jul 5 '16 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.