Redirect URLs in Chrome?
Solution 1
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.
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.
Edit the files are required, and uninstall and reinstall the extension as mentioned above
Solution 2
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 - A Chrome Extension to modify Network Requests.
Currently, You can setup rules for
- Redirect a request URL to another url.
- Block some requests.
- Replace some part in URL with another string. (Even whole URL can be replaced)
- Add/Remove/Modify Headers in HTTP(s) Request and Response. You can setup Header Modification Rules only for specified URLs now.
Screenshots for more understanding:
- List of Rules
- List of Rule Types
- New Redirect Rule
There are lot of things in roadmap to be covered in requestly like
- Setting custom headers (Done)
- Switching User Agents
- Setting parameters in request (Done) Use Redirect/Replace feature to accomplish this.
.. and a lot more.
PS: I have created this So you can blame me if you do not find this helpful :)
Solution 3
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.
Solution 4
A bit late, but this extension should surely do the trick: Redirector.
And it's an arbitrary redirector.
user541686
Updated on September 18, 2022Comments
-
user541686 almost 2 years
Is there any extension to Chrome that will let me force a URL from a particular domain to be redirected to another domain?
(E.g. Redirect
http://www.google.com
tohttps://encrypted.google.com
.)Note: I'm looking for an arbitrary redirector, not KB SSL Enforcer, which only works for the specific task of redirecting to HTTPS.
-
Synetech about 13 yearsYou could also consider using the HOSTS file as another method.
-
user541686 about 13 years@Synetech: Would that redirect just the root page, or anything with a particular domain?
-
Synetech about 13 yearsIt would redirect the whole domain (or subdomain as the case may be).
-
Justin Buser about 12 years@Synetech You're confusing redirecting with resolving, changing the IP address that an address resolves to will not work in this case. He wants to redirect to a different domain, not try to load that domain name on the wrong web server.
-
Synetech about 12 years@JustinBuser, > You're confusing redirecting with resolving No, I'm, not. Under certain circumstances, there is no difference. I use the HOSTS file to redirect all ads to a local web-server that is set up to accept any URL and replace pages with a small tiny bit of HTML that simply says
[ad]
and pictures that are a single transparent pixel. In other words, the ad sites are redirected to localhost (though they easily could be redirected to another machine). -
Synetech about 12 years@JustinBuser, > changing the IP address that an address resolves to will not work in this case. He wants to redirect to a different domain, not try to load that domain name on the wrong web server He has not indicated what the actual domains he wants to redirect from/to are (he used Google as an example), so it may or may not work. That's why I said he could consider it as a comment and not an answer.
-
Justin Buser almost 12 years@Synetech No, I'm, not. Under certain circumstances, there is no difference You're just wrong, they are two COMPLETELY different things. Putting an entry in your hosts file pointing Domain A to IP X changes what Domain A RESOLVES to, that does not REDIRECT anything because it never goes to the original IP. REGARDLESS, that WOULD NOT solve anything, putting an entry for www.google.com with the IP address for encrypted.google.com into your hosts file would result in Chrome trying to load www.google.com from the wrong IP, it would not REDIRECT (i.e. the address would remain www.google.com)
-
Synetech almost 12 years@JustinBuser, it would redirect the browser from the original IP to the specified IP. Imagine digging a ditch to re-route water. You dig a ditch, open the dam, then the water goes to the new spot instead of where it would have gone. I never said anything about 302, so you are only arguing semantics.
-
tony19 over 8 yearsI had no idea encrypted.google.com existed! Cool
-
-
user541686 about 13 yearsOmg cool! How do I install it? (Sorry I have no experience with developing Chrome extensions, haha.)
-
100rabh about 13 years@Mehrdad expanded the answer
-
100rabh about 13 yearsofcourse, if you aren't looking at editing the files, I could've packed the files in to a Chrome Extension....
-
user541686 about 13 yearsBeautiful, thank you so much! It teaches me some JavaScript too! :D
-
100rabh about 13 yearswelcome! I had developed this to learn Chrome extension development. (and to get around coughwebsensecough).
-
V. Alvarado almost 13 yearsPerfect. Exactly what I needed to get around the NYTimes paywall...
-
V. Alvarado almost 13 yearsThanks! BTW, is there a way to debug in chrome the script that is in bg.html?
-
100rabh almost 13 years@YossiFarjoun Yes, you log to error console using console.log
-
apenwarr over 12 yearsNote, I tried this and you don't actually need to use a bg.html for this plugin. You can just assign 'window.location = newurl' instead of doing the message passing. Maybe that wasn't true on older versions of Chrome?
-
100rabh over 12 years@apenwarr You need to go the content script way to inject the code to analyse the page, and at least earlier,
window.location
wasn't possible. Refer to my Stack Overflow question How do I redirect to a URL using a Google Chrome Extension & Content Script?.window.location = newurl
was my first approach while writing this, maybe something's changed since then -
apenwarr over 12 yearsPerhaps this has changed recently. It worked for me in Chrome 16/17.
-
100rabh over 12 years@apenwarr are you doing a simple redirect or are you checking for conditions (as in if you're on domain x & so on)? Can you post a pastebin of your code?
-
user72923 over 11 yearsOpen source? :)
-
lony about 10 yearsWorks great to avoid the Facebook start page, Match: http?://www.facebook.com, Substitute:(.*), Replacement:facebook.com/messages
-
Don Hatch about 10 yearsoh no, it's been removed? looked great from the screenshots! (regexes and such, which is what I need)
-
Martijn almost 10 yearsToo bad Switcheroo doesn't support switching HTTP schemes (as indicated in the example in the question).
-
Sachin over 9 yearsHeaders Modification is now present in Requestly.
-
Adi Ulici over 9 yearsThis is an awesome extension! I logged in just so I can give you a +1, hopefully more people find out about it :)
-
Nakilon over 9 yearsCan it be used to edit the URL of CSS/JS the webpage is trying to load?
-
100rabh over 9 years@Nakilon no, that wont be possible
-
Sachin over 8 yearsRegex Support is also available in Requestly
-
Taylan over 7 yearsAlso too bad it needs permission to "Read and change all your data on the websites you visit" just to redirect.
-
Andrei Kucharavy over 6 years@sachinjain024 the link to github repo is dead as of now.
-
Ryan over 4 yearsAlthough this looked promising, none of this seems to have any effect for me. Maybe Chrome changed.
-
Boris Verkhovskiy almost 4 years