The Computer Oracle

Redirect URLs in Chrome?

-------------------------------------------------------------------------------
Become or hire the top 3% of the developers on Toptal https://topt.al/25cXVn
-------------------------------------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Ocean Floor

--

Chapters
00:00 Question
00:40 Accepted answer (Score 33)
02:49 Answer 2 (Score 17)
04:58 Answer 3 (Score 9)
05:26 Answer 4 (Score 4)
05:43 Thank you

--

Full question
https://superuser.com/questions/284110/r...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#googlechrome #redirection #chromium #googlechromeextensions

#avk47



ACCEPTED ANSWER

Score 34


I had built a Chrome extension which does this.

Note: I built this for just 2 sites - just for the heck of it - by no means it's professional quality™. Please don't flame me for crappy code :)

Edit: Updated to manifest v2, which brings in certain additional restrictions.

manifest.json

{
  "name": "URL Redirect",
  "version": "0.2",
  "description": "Checks URL and redirects as required.",
  "background": { 
     "page":"bg.html"
     },
   "manifest_version": 2,
   "content_scripts": [
   {
     "matches": ["http://*/*", "https://*/*"],
     "js": ["content.js"]
   }
   ],
  "permissions": ["tabs"]
}

bg.html

<html>
  <script src="redirect.js"></script>
</html>

redirect.js

chrome.extension.onRequest.addListener(function(request, sender) {
        chrome.tabs.update(sender.tab.id, {url: request.redirect});
    });

content.js

var pattern=/\bBlocked/;
var viewtext_base_url = "http://viewtext.org/article?url=";
var newurl;
if (pattern.test(window.document.title)) // if it matches pattern defined above
{
  newurl = viewtext_base_url + encodeURIComponent(window.location.href);
  chrome.extension.sendRequest({redirect: newurl}); // send message to redirect

}

To install this, create files with filenames as mentioned above the codeblock.

enter image description here

Once all 3 files are created, Click on Chrome Menu → Tools → Extensions. Click the "+" on Developer Mode. Click on Load Unpacked extension and point to the directory where the files are stored.

enter image description here

Edit the files are required, and uninstall and reinstall the extension as mentioned above




ANSWER 2

Score 20


I know I am a bit late in the game to answer this question Still I would like to answer this for future readers. Have a look at

Requestly - Open Source Chrome Extension to modify Network Requests.

Github Repo - https://github.com/requestly/requestly

Currently, You can set up rules for

  1. Redirect a request URL to another url.
  2. Block some requests.
  3. Replace some part in the URL with another string. (Even the whole URL can be replaced)
  4. Add/Remove/Modify Headers in HTTP(s) Request and Response. You can set up Header Modification Rules only for specified URLs now.

Screenshots for more understanding:

  • List of Rules

List of Rules

  • List of Rule Types

List of Rule Types

  • New Redirect Rule

Creating a Redirect Rule

There are a lot of things in the roadmap to be covered like

  • Setting custom headers (Done)
  • Switching User Agents
  • Setting parameters in request (Done)

.. and a lot more.

PS: I have created this So you can blame me if you do not find this helpful :)




ANSWER 3

Score 9


I have developed a pre packaged user friendly redirector called Switcheroo if you're interested:

Setup custom redirect rules for any http request i.e pages, scripts, images etc. Uses a simple string replace to do this.




ANSWER 4

Score 4


A bit late, but this extension should surely do the trick: Redirector.

And it's an arbitrary redirector.