Source code – addons.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!
Version 1.7.1 — May 30, 2009
Two tiny bugfixes from version 1.7.
- An error message was printed to the Error Console ‘Redirector.unLoad() is not a function’ when the Options dialog was closed.
- For new users, the first time the options dialog was opened, it contained one item where everything was marked as ‘undefined’.
Version 1.7 — May 29, 2009
This version updates Redirector to support Firefox 3.5, while dropping support for the 2.0.* series. The version does not add any new user features. Instead it is a technical update, with a lot of the core functionality re-written to pave the way for the upcoming 2.0 release which will contain many new features. As of this release the “only if link exists” option is no longer available and redirects on POST requests will no longer work. This is a side effect of the new implementation, since I have not heard from a single user that uses these features I decided that it was ok to remove them. Contact me if that is a problem for you.
Although not really “user features”, here is a list of the technical changes for those interested:
- Redirector is now an implementation of the nsIContentPolicy interface. Before there were different ways used to catch requests depending on whether it was opened in a new tab, new window, came from the outside etc. This new implementation works fully for any case and makes the code a lot cleaner and maintainable. It also makes sure that the requests to the original url are never made, they are blocked before they leave the browser which was not always the case in the old version.
- The format of the redirects is no longer JSON, and is not eval’d to import. This was taken out for security reasons, since v2.0 will support importing redirects from others, and it is not safe to eval something from the outside.
- The Redirector class itself is now a javascript XPCOM component, which makes it a true global object, whereas before there were multiple instances which communicated through preferences and preference listeners (a big hack basically).
Version 1.6 — May 24, 2008
Compatible with Firefox 3.0.*.
Version 1.5.2 — January 28, 2008
This version pretty much adds all features and fixes that people have been asking for, that’s why I bumped the version all the way up to 1.5.1. Here’s what’s new:
- Firefox 3 compatibility
- Improved UI in the Redirector settings window
- Access Redirector settings through the statusbar icon. Left click disables Redirector, right click shows settings.
- Ability to hide context menu and status bar through about:config, just search for redirector and you’ll find the config options.
- Replacement chars ($1,$2…) for wildcards as well as regular expressions.
- Help file included with examples, accessible through the Redirector settings window.
- Possible to add exclude patterns in addition to the normal include patterns, this makes capturing certain things simpler.
- And last but not least, redirects now work when opening new windows, new tabs, middle clicking links, opening bookmarks and opening urls from other applications.
One feature was removed in this version, that is the xpath redirect urls. The reason is that as far as I know no one was using the feature and it was causing some problems so I decided to remove it. I think this addon is pretty much feature complete at this point, I don’t think I’ll work more on it except to fix bugs from now on. Enjoy
Version 1.5.1 — January 23, 2008
This version was what is now 1.5.2. It was rejected at AMO, so I changed it and released as 1.5.2. Version 1.5.1 was available on this site in the meantime.
Version 1.5 — January 8, 2008
This version was what is now 1.5.2. It was rejected at AMO, so I changed it and released as 1.5.1. Version 1.5 was available on this site in the meantime.
Version 1.0.2.1 — October 5, 2007
Bugfix release. Two bugs:
1. Fix missing statusbar icon on linux
2. Fix error that came in the error console when Redirector was disabled
Version 1.0.1 — October 2, 2007
Bugfix release. Two bugs fixed:
1. The stop button was always active and it looked like pages never finished loading.
2. There were some memory leaks when opening and closing new windows.
Version 1.0 — September 28, 2007
Three new features in this version:
1. Instant redirects instead of loading the page before redirecting.
2. XPath expressions to specify redirect urls.
3. Redirect url can now be a relative url and will then be resolved against the first url.
Details about these features have been included in the main extension description.
Version 0.9.2 — August 7, 2007
This version adds an ‘Add…’ button to the main Redirector window (Tools -> Redirector) so you can enter urls and patterns directly from there. If you do it there you of course won’t get the example url filled in automatically.
Version 0.9.1 — June 2, 2007
All functionality working. Not yet 1.0 because I have to fix some minor UI things (i.e. make it not be butt-ugly) and some other minor things.
Leave a Comment
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
Hi Jason.
This error has been found before and will be fixed in the next release.
Ok
http://feeds.hwupgrade.it/rss_hwup.xml
Thanks for any suggestion
Hi,
I think it’s a mode to bypass your addon.
The link is http://feeds.hwupgrade.it/rss_articoli.xml
Thanks
Ops, double comment, excuse me.
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.
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
Will there be an update for firefox 3.6 compatibility?
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.
Any chance you will be updating this excellent add-on for Firefox 3.6+? I would really appreciate it.
I’ll second that. PLEASE release a Firefox 3.6 version of this amazingly useful addon.
See comment above yours, it’s already in the sandbox
Cool, works like a charm, thanks so much!!! I really love this add-on, it’s so useful!
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.
@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…
#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.
@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.
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
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?
@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.
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..
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.
@Peter: This only redirects documents, that is the url in the browser window, or in frames/iframes.
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
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£).
Any chance of porting this to Chrome / Chromium please?
This extension is a blessing for craigslist, but I rarely use Firefox anymore.
@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.
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
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.