I want to block certain URLs on browsers. I don't want to block whole site. For example, I want to block Google Reader, but not whole Google domain. Is there any way I can do it?


The answer will only SLIGHTLY differ by the operating system you are using. I'm running Ubuntu on a powerpc :p but in general the same rules apply on windows and mac as well. If these instructions do not work for you then I will adapt this answer for your OS. For now here is the Linux method.

The only way I have found after hours of searching, to do this, is to install privoxy.

Once you install privoxy you need to edit the /etc/privoxy/config file in the following manner:
1) Find where it says

#listen-address  localhost:8118

and uncomment this line so that it says

listen-address  localhost:8118

2) Add the following lines to the bottom of this config file:

actionsfile blacklist.action   
actionsfile whitelist.action   

3) Now you need to create these action files in a text editor as root: a) gksu gedit /etc/privoxy/blacklist.action and add the following

{ +block }

anything you add under the {+block} line will be blocked

b) Respectively you should create the whitelist.action file

gksu gedit /etc/privoxy/whitelist.action

and add the lines

{ -block }

or whatever you find privoxy blocking that you want to protect.

After you have saved the three files you have to restart privoxy:

sudo /etc/init.d/privoxy restart

and you have to make sure that your proxy settings in your browser or in your network configurations are correct, adding localhost as the proxy and 8118 as the port number will be all you need.

The SERIOUS and UNFORTUNATE drawbacks to privoxy is that it is a proxy so all anyone needs to do to stop it working is turn it off, or use a different browser. I am still searching for a way to add privoxy to my router or to somehow run it , not as a proxy, but as my default on port 80, then you could lock down the config files so that no one could change them.

This is the closest you will find to an answer to your problem.

If it doesn't appear to be working at first don't forget to flush your browser's cache because the pages you have blocked may show up from cache even after they have been blocked.

also you might want to turn this off:

make sure that enforce-blocks 1 is set to 1 in the /etc/privoxy/config file

enforce-blocks 1

Otherwise, when the page blocked warning comes up, it will have an option to go to the blocked page anyways despite being blocked and completely make privoxy meaningless.

| improve this answer | |
  • 1
    Concerning "all anyone needs to do to stop it working is turn it off...", use iptables(1) to whitelist traffic only to the proxy on that machine for the user about which you care. – Limited Atonement Jun 29 '16 at 2:49
  • @LimitedAtonement, could you, please, provide the relevant iptables rules to force all the traffic for a particular user to the privoxy/e2guardian (let's assume they run on localhost:8080). Thanks. – user1876484 Oct 18 '19 at 10:41
  • @user1876484 Sorry, I don't have the rules anymore, and don't remember how to do it. cyberciti.biz/tips/… ? Good luck. – Limited Atonement Oct 19 '19 at 15:51

If you want to block a specific domain system-wide, you should use the hosts file (See here). So, if you want to block Google Reader, you'd add the following to your hosts file:    reader.google.com

However, there are restrictions on this. While you can block subdomains and domains, you can't use the hosts file to block subdirectories (i.e., www.example.com/subdirectory). In the case of Google Reader, one could simply navigate to www.google.com/reader to get around the blocking. A more comprehensive solution may be to use something like Privoxy to control web access.

| improve this answer | |
  • 1
    I added the site I want to block to the hosts file . www.reddit.com . Then I disconnected from the network and connected again. But I still have access to the site. Do I need to restart my computer? How do I cache/reference/refresh the hosts file once it's been edited? – Joshua Robison Apr 29 '13 at 1:21
  • 1
    wait a second?!?! the host file can not block urls can it. Like www.apple.com/itunes/ ... it can block www.apple.com but not www.apple.com/itunes/ right? – Joshua Robison Apr 29 '13 at 2:15
  • what file do I need to edit to add a blocked page to privoxy? @clipo13 – Joshua Robison Apr 29 '13 at 4:37
  • @JoshuaRobison As far as I know, changes to the hosts file take effect immediately. However, applications like web browsers may have cached the old version, so try closing and reopening the browser you're using. See here for more about that. With regards to Privoxy, I don't know enough about it, sorry. You might want to check out their quickstart for more about what config files you need to modify. – clpo13 Apr 29 '13 at 19:19
  • actually I found out. It is fairly simple. You only have to make a file called blacklist.action and whitelist.action ... anyways. I'll make an answer for it – Joshua Robison Apr 29 '13 at 23:49

If you are using Firefox or Google Chrome, you can use a customisable "ad-block" extension to do this. Ad-blocking extensions normally come with a whole range of websites that they block out-of-the-box, however most customisable ones will let you remove this default list and add just the specific websites you don't want.

| improve this answer | |

The easiest solution to your issue would be to use an extension/script for your browser.

I have used Chrome Nanny to do the trick in Chrome. LeechBlock seems to be the Firefox alternative. Both support wildcards in domains and you can set specific time periods in which to block a URL.

| improve this answer | |
  • This works, but only for the browsers you install the extension in, and only if the browser wasn't started in safe mode. – Andrew Lambert Feb 25 '12 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.