5

This question refers to FireFox v25 in my case.

A Wiki Workspace used by me, changed its name from

https://wikis.mycompany.com/teamcollab/wiki/MyProduct+Alpha+QA:Test+Automation

to

https://wikis.mycompany.com/teamcollab/wiki/MyProduct+QA:Test+Automation

omitting the word "Alpha" from the Wiki's name and URL.

I am frequently returning to pages on the wiki, by starting to write sections of the page's URL or Title in the address bar, which auto-suggests me relevant pages.

Now, this feature is broken, as all my pages are leading to the wrong URL and as a bonus, I now have duplicates of the new wiki and the old wiki in the history.

Since the History is saved in the

I want to be able to do the following (which is available for Bookmarks)

1) Export all the History I have 2) Manually go into the History and replace the URL and Title contents. 3) Import the new History.

or alternatively, what is a proper sqlite sql query to change the history.

I looked for a suitable Firefox add-on, but couldn't find one so far. This can also be a good option.

Thanks.

RaamEE

RaamEE
  • 482

4 Answers4

5

As already answered by "RaamEE". You can follow that approach.

But this is little simple where we can directly run UPDATE command on sqlite(Db of firefox). Update on sqlite is very easy and we can verify the change as well. Just run SELECT command to check the changed history.

Important

  • Quit Firefox.
  • Find Firefox profile folder.
  • Make a backup.

Process on MAC & worked for me

  1. Quit Firefox
  2. cd /Users/{USER_NAME}/Library/Application Support/Firefox/Profiles/oicj7ndj.default (oicj7ndj will be different for you)
  3. Make a backup: cp places.sqlite places.sqlite.bak
  4. Run SQLite: sqlite3 places.sqlite
  5. To change: UPDATE moz_places SET url=replace(url, 'OLD_STRING', 'NEW_STRING') where url like "%OLDSTRING%";
  6. To validate: select * from moz_places where url like "%NEW_STRING%"
  7. quit from SQLite and start Firefox
Garry
  • 166
2

------IMPORTANT------

Save a copy of places.sqlite before you begin. Save 2 copies if needed. Use at your own discretion

------IMPORTANT------

I chose the dirtiest quickest solution. running 400 SQLite UPDATE commands to change 400 records.

1) copy a backup of places.sqlite from /Users/YourUserName/Library/Application Support/Firefox/Profiles/7skm4kzn.default/places.sqlite (MacOS system. The last directory differs between profiles) to places_bak.sqlite

2) run a HERE script to select the records and output into file

#!/bin/bash

sqlite3 places.sqlite << HERE > results.sql
        select id, url from moz_places where url like '%MyProduct+Alpha+QA%';
HERE

3) Use vi and the next substitution to modify the urls (I didn't need to touch the Title)

:%s/\([0-9]*\)|\(.*\)MyProduct+Alpha+QA\(.*\)/UPDATE moz_places SET url='\2MyProduct+QA\3' WHERE id=\1;/gc

This will remove the word "+Alpha" from the URL and create a new set of UPDATE commands which in turn you can dump into the DB file using this HERE script

#!/bin/bash

sqlite3 places.sqlite << HERE
        `cat results.sql`
HERE

4) Copy & Replace the original places.sqlite under your profile path. I suggest you shutdown firefox before overwriting the original file.

RaamEE
  • 482
1

I had the same question as you had, but it turned out that what was wrong was the question. I found a better approach to deal with the renaming of a wiki: the Redirector web browser plugin.

You can basically have your browser redirect you using regular expressions. The best thing is that not only does it work with history URLs, it also works with any other URL, so if you follow links to the old wiki from anywhere else, they get right too.

Gallaecio
  • 111
  • 3
0

The other answers are not bad, but since Firefox 50 there is an url_hash column in moz_places table inside places.sqlite that also needs to be updated for everything to work properly. Based on initial testing it affect visited link highlights at least.

There is also the rev_host column which stores the host name in reverse.

There is also the favicons.sqlite file containing moz_pages_w_icons table that also has the page_url cloumn for all visited pages.

There is this sqlite3 extension to generate it:
https://github.com/bencaradocdavies/sqlite-mozilla-url-hash

Full instructions for debian-like OSes:

  1. install dependencies:
    apt update && apt install git sqlite3 libsqlite3-dev libc6-dev make gcc binutils
  2. get the url hash generator project source:
    git clone https://github.com/bencaradocdavies/sqlite-mozilla-url-hash.git && cd sqlite-mozilla-url-hash
  3. build it:
    make
  4. connect to Firefox's sqlite database:
    sqlite3 path/to/profile/places.sqlite
  5. import the extension we built:
    sqlite> .load ./sqlite-mozilla-url-hash.so
    • subdirectory update only:
      sqlite> update moz_places set url = replace(url, 'https://url/old', 'https://url/new'), url_hash = 0 where url like 'https://url/old%';
    • hostname as well:
      sqlite> update moz_places set url = replace(url, 'https://host.old', 'https://host.new'), rev_host = 'dlo.tsoh.', url_hash = 0 where url like 'https://host.old%';
  6. fix the url hash:
    sqlite> update moz_places set url_hash = hash(url) where url_hash <> hash(url);
  7. sqlite> .exit

Lets also fix favicons:

  1. sqlite3 path/to/profile/favicons.sqlite
  2. sqlite> update moz_pages_w_icons set page_url=replace(page_url, 'https://url/old', 'https://url/new') where page_url like 'https://url/old%';
  3. sqlite> .exit

If someone wants to tinker with python then there is this code as well to generate it:
https://gist.github.com/boppreh/a9737acb2abf015e6e828277b40efe71

NLZ
  • 1