1

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,297
  • 10
  • 57
  • 69
Rob W
  • 2,083
  • 2
  • 22
  • 23
  • Just in case you know a bit SQL: http://forensicswiki.org/wiki/Mozilla_Firefox – Arjan Jul 27 '15 at 13:47
  • Most of the files you need are in your Profile directory, and most are SQL data-bases, eg `places.sqlite`. You can use the **SQLite Manager** add-on to update these, but you need familiarity with SQL. – AFH Jul 27 '15 at 13:48
  • @Arjan & AFH Not everything is in a sql database, e.g. the active tabs are in sessionstore*.js in the profile directory. I was hoping that someone had already solved this problem before creating the queries myself. – Rob W Jul 27 '15 at 13:52
  • you dont need to know sql apart from "dump". Do `sqlite3 places.sqlite .dump` then edit with sed and pipe back into sqlite3. – meuh Jul 27 '15 at 14:15

1 Answers1

3

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,083
  • 2
  • 22
  • 23