2

A website that I visit often has changed its domain name (old.example.com -> new.example.com). How can I easily rewrite all entries in Firefox's history and sessions (active tabs), as if the website was always using the new domain instead of the old one? You may assume that Sync is not enabled.

My situation is similar to Remove URLs by domain from Firefox history and awesome bar. That accepted answer is insufficient, because it only explains how to delete the items, while I want to know how to rewrite the items. And that the question does not even mention rewriting of active tabs (I have dozens of such tabs, spread across tab groups).

Dave
  • 25,513
Rob W
  • 2,283
  • 2
  • 24
  • 23

1 Answers1

5

I've just rewritten my history and tabs. It took two passes, my first attempt failed (=full history was lost), so make sure that you've got a backup of your profile before following the following steps.

Steps to migrate your history from http://old.example.com to https://new.example.org:

  1. Quit Firefox.
  2. Create a backup of your profile (at least sessionstore.js, places.sqlite and cookies.sqlite).
  3. Edit sessionstore.js and replace all occurrences of the old domain with the new one.
  4. Delete places.sqlite-shm and places.sqlite-wal if they exist.
  5. Edit places.sqlite (e.g. using sqlite3) and update the moz_favicons, moz_places and moz_hosts tables. Note that some columns have an uniqueness constraint, so if you've visited the new site, delete the new history items (otherwise you may get an error like "Error: UNIQUE constraint failed: moz_favicons.url").

    -- Website icons (favorites and tabs)
    delete from moz_favicons where url like 'http://new.example.org%';
    update moz_favicons
      set url=replace(url, 'http://old.example.com', 'https://new.example.org')
      where url like 'http://old.example.com%';
    
    -- History
    delete from moz_places where url like 'https://new.example.org%';
    update moz_places
      set url=replace(url, 'http://old.example.com', 'https://new.example.org'),
      rev_host='gro.elpmaxe.wen.'        -- ".new.example.org", reversed
      where rev_host='moc.elpmaxe.dlo.'; -- ".old.example.com", reversed
    
    -- Host metadata, affects autocompletion in URL bar
    delete from moz_hosts where host='new.example.org';
    update moz_hosts set host='new.example.org' where host='old.example.com';
    
  6. Delete cookies.sqlite-shm and cookies.sqlite-wal if they exist.

  7. Edit cookies.sqlite:

    delete from moz_cookies where host like '%.new.example.org';
    update moz_cookies
      set baseDomain='example.org',
      host=replace(host, '.old.example.com', '.new.example.org')
      where host like '%.old.example.com';
    

    Note: If you are migrating from http to https, you might want to set the isSecure column to 1, to restrict the cookie to https.

  8. Now start Firefox, and now your history and active sessions should be using the new domain.
Rob W
  • 2,283
  • 2
  • 24
  • 23