msgbartop
A site for my programming pet projects
msgbarbottom

Redirector

Source codeaddons.mozilla.org page

This was done as a request for someone on the Mozillazine forums.

The extension allows you to specify patterns for pages that should be automatically redirected to other pages. E.g. you always want http://example.com/foo.html to redirect to http://example.com/bar.html.

This can be useful for instance to skip confirmation pages after posting messages on message boards, skipping ad pages that appear before you can view content on certain sites, redirecting from http to https on sites where you always want the https version, redirecting from one hostname to another for proxy servers, or just anywhere where it takes you two or more clicks to get to what you want.

The extension supports both wildcards and regular expressions in patterns. Regular expressions support capturing parantheses so you could define the pattern: http://foo.com/bar.php\?id=(\d+) and define the redirect as http://bar.com/baz.php?id=$1. In that case http://foo.com/bar.php?id=1234 would automatically redirect to http://bar.com/baz.php?id=1234. As of version 1.5 wildcards can also use $1,$2 in the redirect urls, $1 is the contents of the first star match, $2 of the second and so on.

To add a new redirect, right click either anywhere on a page and click ‘Add current url to Redirector’ or right click on a link and click ‘Add link url to Redirector’. You can also add urls from Tools->Redirector->Add… but then you won’t get the example url filled in.

To edit and delete redirects, goto Tools->Redirector, or choose Options on the Addons window.

To disable Redirector temporarily, click on the R that’s in your statusbar. Right clicking the icon opens the Redirector options window.

Works with Firefox 3.5 – 3.5.*
Latest version: 2.0

Download

Releate notes: version 2.0 — October 26, 2009

Finally, here is version 2.0. This version includes several of the most requested features and bug fixes as well as some performance optimizations.

  • Option to unescape matches in include patterns. This means that if you have a pattern like http://foo.com/?url=* which redirects to $1 (the content of the *) and the match is escaped, like http%3A%2F%2Fbar%2Ecom%2Fpath then previously the redirect would fail. Now you can use the option “Unescape matches” which will turn http%3A%2F%2Fbar%2Ecom%2Fpath into http://bar.com/path which makes it usable as a redirect target.
  • It is now possible to re-order the redirects.
  • Individual redirects can be disabled, as well as disabling all redirects at once.
  • Import and export of redirects to text files is now possible.
  • Redirects now work on url’s that are the result of 30x redirects from web servers. Previously when you entered for example http://foo.com into the address bar and the website sent back a 301 redirect to http://foo.com/new/path then the http://foo.com/new/path url was never checked against the redirects. Well, now it works.
  • Improved GUI. All configuration options are for example now available in the GUI, it is split up into tabs instead of having everything in the same place and the window is resizable.
  • Improved performance. Both wildcard and regular expression patterns are now stored as compiled regular expressions, instead of being created from string patterns during every single redirect. Some more checks have also been added to make sure that we exit as soon as possible in those cases where redirects should not apply.
  • More protection from shooting yourself in the foot. The dialog to create redirects will now warn you if your pattern doesn’t match your example url, or if your redirected url also matches the redirect, possibly causing an endless series of redirects. During redirection it is also checked whether the redirected url matches the same redirect that created it, if so a warning is displayed to the user and the redirect is disabled. This will stop the user from issuing endless requests to the same url. It is still possible to have one redirect from A to B and another from B to A, the current safeguard functionality doesn’t detect cycles like that.
  • Refactored to get rid of ‘eval’ and ‘wrappedJSObject’ so it passes all validations at AMO.

Note: This new version only supports version 3.5.* of Firefox. It is highly likely that it would work without problems on the 3.0.* series, but since I am not putting in the effort to test on those version, I will not report them as being supported. If anyone feels like testing this, let me know and if everything works I’ll add them as supported versions on AMO.

Anyway, enjoy!

Show release notes for older versions

Reader's Comments

  1. |

    Running on FFX 3.5.7 I get this error when trying to edit an existing redirect:

    uncaught exception: [Exception... "'[JavaScript Error: "Redirect is not defined" {file: "chrome://redirector/content/code/redirect.js" line: 47}]‘ when calling method: [rdIRedirect::clone]” nsresult: “0×80570021 (NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS)” location: “JS frame :: chrome://redirector/content/code/settings.xul.js :: anonymous :: line 161″ data: yes]

    Line 0

  2. |

    Hi Jason.

    This error has been found before and will be fixed in the next release.

  3. |

    Ok
    http://feeds.hwupgrade.it/rss_hwup.xml
    Thanks for any suggestion

  4. |

    Hi,
    I think it’s a mode to bypass your addon.
    The link is http://feeds.hwupgrade.it/rss_articoli.xml
    Thanks

  5. |

    Ops, double comment, excuse me.

  6. |

    Hi,
    I find a solution using recursive mode but it cause the error “This will cause an endless loop and so the redirect has been disabled to prevent this from happening. You should edit this redirect to fix it”.
    I create a rule for any substitution.
    Example
    http://www.abcdXXefghXXilXXmn.com
    *XX*, $1/$2 > http://www.abcd/efghXXilXXmn.com
    then http://www.abcd/efgh/ilXXmn.com
    and then http://www.abcd/efgh/il/mn.com
    If you add a little option to deactive the error or better to stop the execution before n pass with a selector.
    I hope this solution is more simple to implement.

  7. |

    This script does work really well. One gotta know how to use regexp though.

    Do you think it would be possible to modify it to redirect urls found in javascript code too ?

    Cheers,

    Gabriel

  8. |

    Will there be an update for firefox 3.6 compatibility?

  9. |

    Hi John. It’s already there, it’s just in the sandbox waiting for approval. If you go to https://addons.mozilla.org/en-US/firefox/addons/versions/5064

    you can see version 2.0.2 at the top, that works for 3.6. You probably have to check some “i know this is experimental” checkbox or something like that to be able to download it though.

  10. |

    Any chance you will be updating this excellent add-on for Firefox 3.6+? I would really appreciate it.

  11. |

    I’ll second that. PLEASE release a Firefox 3.6 version of this amazingly useful addon.

  12. |

    See comment above yours, it’s already in the sandbox :)

  13. |

    Cool, works like a charm, thanks so much!!! I really love this add-on, it’s so useful!

  14. |

    For some reason, when using the newest version (the one that works on FF3.6), Redirector causes redirected pages to load in a new window.

    i.e. if a rule kicks in to redirect, it works as expected and redirects to the proper URL. However, it ALSO opens a copy of the redirected URL in a new Firefox window.

    I can certainly send you an export of my export that does this if needed.

  15. |

    @Ryan: I’ve gotten one report about this before, but it only happened when you were opening url’s from outside Firefox, e.g. you clicked a url in MSN Messenger or something like that. Does this happen for you when you are entering urls yourself in Firefox/clicking links inside Firefox? If it does then please send me an example so I can try it out.

    On a more technical note [you can stop reading now :) ] this happens because in Firefox 3.6 it seems that when an url is opened from the outside Firefox opens a new hidden window automatically as well as send the url to any existing Firefox window. I get notification of the new url in two places (both windows) and redirect in both places which causes the new window to become active whereas if I don’t redirect Firefox shuts down the new window before it is ever displayed. Detecting this is pretty hard since the notification I get is just a url and I need to figure out if that url is also being/has been loaded in a different window.
    If any addon developer have any ideas about this then please let me know, because so far I’ve got nothing…

  16. |

    #einar You are absolutely right. Only when I make a desktop shortcut (or use an external application, as my case is) does the second window open.

    Both clicking a bookmark/link and typing in the URL manually behave perfectly.

    I hope you are able to find a way to work around this issue. Currently my biggest reason for using Redirector is to change URLs that are hard-coded into external applications.

    As for a possible solution, couldn’t you wait until the server returns a header before redirecting? I assume that is when Firefox shuts down the second process (the second hidden window).

    Granted, you would lose some time, since you have to wait for the server to respond, but it wouldn’t be much time assuming the server headers aren’t abnormally full.

  17. |

    @Ryan: Unfortunately I can’t wait for a header before redirecting. Redirector is implemented as a content policy in Firefox, which means that the request to the original url is blocked before it ever leaves the browser. This is a feature, a feature that a lot of people care about.

    As far as I can tell (and I haven’t spent much time on this yet) the new window remains activated because I reject the url being loaded and start loading a new one. If I accept the url being loaded then the window is never shown. I could probably come up with some heuristic, e.g. this is a new window with only one tab, I should probably check if there exists another window where the same url is being loaded etc. But another problem here is that I really want to do as little as possible during the checking of an url, since this is code that runs for every single loaded url in your browser and so could have some performance implications if I start looking for windows or waiting for some stuff.

    I’ll ask around about it on some Firefox forums, this behaviour clearly wasn’t there in 3.5, so maybe someone can tell me what happened.

  18. |

    Hi Einar,
    I need redirector works for my problem so I open the js file and I add some function and all works with Unescape Matches checked. Then I wanted add a second Unescape Matches option but I can’t manage the .xpt file and my works stop. If you mail me I send you my mod so you can add to official softwar if you want.
    I add the option to UI changing unascapeMatches in unascapeMatchesA and unascapeMatches and I modified all the js file with this var. I hope you want help me.
    Bye

  19. |

    Hi Einar,

    Thanks for a very nice add on!

    I have some small problems though and I am not sure if it’s a bug or just a missconfiguration from my side.. Maybe you can help me sort it out?

    I would like to redirect everything from a website to another e.g.

    http://www3.interscience.wiley.com/*

    to

    http://www3.interscience.wiley.mylibrary.com/*

    to use my library’s proxy to access articles.

    (include: first line above, redirect to: second row above, everything else blank (use wildcards))

    If I browse the website from within it works great, but when I try to access anything (e.g. http://www3.interscience.wiley.com/journal/123218273/abstract) from outside the browser e.g. google, I just end up on: http://www3.interscience.wiley.mylibrary.com/*

    Am I missing something?

  20. |

    @Oscar: Are you sure these are the patterns you’re using? The redirect to should at least not be

    http://www3.interscience.wiley.mylibrary.com/*

    but should be

    http://www3.interscience.wiley.mylibrary.com/$1

    instead. (You use $n in the redirect-to url to indicate which * in the include pattern to fill in from, first star => $1, second star => $2.

  21. |

    Yes, now it works! Thanks a lot! I’ve been scratching my head for a long time about this one.. I guess it’s not too easy if you don’t know what you’re doing.. :P

  22. |

    Does this addon only redirect the URL in the browser window, or will it redirect any requested URL? eg JS includes, XHR etc etc?

    I am only asking because I want to redirect a JS include from one server to my localhost to debug something… and its not redirecting.

  23. |

    @Peter: This only redirects documents, that is the url in the browser window, or in frames/iframes.

  24. |

    Hey einar – thanks for a great app.
    I would love to redirect all addresses from
    imdb.com to pro.imdb.com
    Like http://www.imdb.com/title/tt1139797/
    to: http://pro.imdb.com/title/tt1139797/
    Thanks

  25. |

    Hello and thank you for the addition of manual sorting and thank you for adding functions to test endless loop !

    Redirector :: Add-ons for Firefox Version 2.0.2 — January 18, 2010 — 84 KB

    The 2 tests endless loop could they be displayed with the button “Test Pattern” (result of 2 tests always displayed) and when i try to validate the changes with “OK” (result of 2 tests displayed in case Error detected) and not separately (1 test with the button “Test Pattern” and the other test with the “OK”) ?

    Can you please add a “+” and “-” ( “-” gray with 1 line, respectively) in front or behind the lines “Include Pattern” and “Exclude pattern” to add or remove a line respectively ? Especially handy and easy to use with “Wilcard” = “*” (rather simple to understand and use).

    Can you please add a sign like “╫▓╫” on the line almost completely right between 2 rules to tie them together with an option to apply all rules tied together ? Leave an empty frame on all lines = style mortise and tenon with locking, operated by clicking or dragging the fasteners with the mouse.

    Thank you very much ! I’m french, sorry for my english (translate with the help of G00GL£).

  26. |

    Any chance of porting this to Chrome / Chromium please?

    This extension is a blessing for craigslist, but I rarely use Firefox anymore.

  27. |

    @Fred: Sorry, I doubt all these changes will make it into Redirector. For more complex patterns that should be able to match one or more patterns you’ll have to use regular expressions and use their capabilities to match one or more things (the | operator). You’re right though that the test pattern should also do the recursive test, I’ll look at that in a future version.

    @Amiga: I don’t have any idea about the state of Chrome extensions or what they are capable of so it’s highly unlikely that this will be ported anytime soon. But what I will do is look at Chrome and try to evaluate how much time and effort it would be to port.

  28. |

    einar – I like it, but wish it could be used to rewrite _every_ request made on behalf of the browser. I’m not even sure if that’s possible with the plugin interface.

    The specific problem I’m trying to address is to force Flash loads of my .swf files to debug versions of the same. Since my .swfs are loaded via a third party one, I’m unable to control that end.

    ie http://blah.me.com/flash/SomeSwf.swf to http://blah.me.com/flash.debug/SomeSwf.swf

  29. |

    I`ve found bug in latest version (2.0.1) – the first item in the list of redirects is not editable, only second or next one.

Leave a Comment