1

What I want: When users type a certain URL, say, reddit.com or cracked.com, that they get automatically redirected to another site... say khanacademy.org or something.

I am volunteering at my local library setting up some computers and they wanted to "encourage" the kids to visit certain sites over other ones. Ethics aside, I was wondering how I should go about implementing this other than a ban in the hosts.txt file.

PS -- Did I say I was a monster for banning Reddit from kids? Yes yes, sorry again... just think of me preventing kids from making more inane rage comics, novelty accounts, and pun threads to fill the site. ಠ_ಠ

binarysolo
  • 13
  • 1
  • 1
  • 3

3 Answers3

2

One of the easier way is to use the hosts file, it's easy to circumvent if you know the IP of the site you want to go to. Another option is http://www.opendns.com/.

Nifle
  • 34,203
  • 26
  • 108
  • 137
  • 1
    But: the hosts file will only work if the target site is not on some shared hosting. Like `ping gmail.com` might yield `74.125.79.18`, but lacking the HTTP `Host:` header, `http:\\74.125.79.18` will take one to Google Search instead: http:\\74.125.79.18 (Okay, 6th edit: no IP addresses allowed in links in comments?) – Arjan Aug 14 '11 at 08:32
  • I couldn't find information about *redirecting* on OpenDNS. (Even then: it's a nice solution for schools, even more if one can set up something in a router, to outsmart the kids!) – Arjan Aug 14 '11 at 08:37
  • @Arjan - I'm pretty sure you can redirect a url when you block it. – Nifle Aug 14 '11 at 08:43
  • Hrm, so does it have to be IP dependent? Say if I want to direct to a specific page instead of just the base site? – binarysolo Aug 14 '11 at 08:44
  • @Binary - Yes for a quick solution I'm afraid so. – Nifle Aug 14 '11 at 08:49
  • Oh wells... for a more complicated solution, is there a way to direct it to a more specific page? (Say a Terms of Use page in a site?) That was the library's first request, but understandably I'll opt for something easy if the harder option is a LOT more work. – binarysolo Aug 14 '11 at 08:50
  • @Binary - The correct way to handle this is to set up a proxy server for the library. Then you have full control of all the traffic. But take a better loo at the free openDNS solution, it might be enough. – Nifle Aug 14 '11 at 09:06
  • Okay -- yeah I'll prolly start with the hosts.txt file and Google up the correct way to handle it. :) – binarysolo Aug 14 '11 at 09:08
  • for some reason google chrome ignores your hosts file; at least under windows ... – iHaveacomputer Dec 01 '11 at 04:00
0

As @Arjan pointed out in his comment, the hosts solution does not work for sites that are behind a CDN or in a shared hosting. Another solution is to use a browser extension, for Chrome, you can use the webRequest API:

background.js:

chrome.webRequest.onBeforeRequest.addListener(function (details) {
  return { redirectUrl: 'https://bar.com'};
}, {urls: ['https://foo.com/']}, ['blocking']);

manifest.json

{
  "name": "redirect",
  "description": "Redirect foo to bar.",
  "version": "1.0",
  "permissions": ["webRequest", "webRequestBlocking", "https://foo.com/"],
  "background": { "scripts": ["background.js"] },
  "manifest_version": 2
}

Put these two files in a folder and load the extension by going to Chrome > Settings > Extensions > "Load unpacked extension", and select the directory where the files are.

synack
  • 101
  • 1
0

The simplest way I can think of is to put the hostname in your hosts file with the ip address of the site you want to redirect it to.

Col
  • 7,037
  • 21
  • 21