Networking - Linux

i redirected a one website called facebook to another website
google through hosts file. If it’s possible making time delay?
for an example i entered the website facebook in browser, it goes the fb site
after 2 or 3 seconds it’s redirected to google. how to do this?

1 Like

You wanted to know about redirection right ?

1 Like

Yes
redirection with specific time

I don’t see how you could do a delay with hosts file.
You could possibly set up a local apache proxy to fb site and then with a script delay redirect to google.com.

facebook would be in hosts file to point to localhost, the apache proxy should be set up so that it would still resolve to real facebook IP address.

2 Likes

@Henrik_Iivonen

Yes, you absolutely correct, setting Apache proxy to an Facebook site will work fine, but how he would redirect to Google.com after certain given time? I mean how script would be and how he will integrate with Apache? Even I would like to know the solution, it would be great if you could provide some clear explanation on this…

thanks

Don’t know yet, it’s still just an idea in my head :smile:

@Henrik_Iivonen - :wink:

Idea was good, but very difficult to implement and I am damn sure there isn’t any way…it’s just an idea…:slight_smile:

One would most likely need a local html file to served with javascript delay and then embedd facebook page inline. FB might have code that blocks this behavior and they also have their own timers wich would most likely break this.

1 Like

@Henrik_Iivonen
I tried this before, but Facebook blocked such behavior earlier, so as I said above, no way to implement this…but still I am sure there is a way, but right now don’t know how to do it…

How about putting HTTP_REFERER rule before proxy?
If referer is facebook.com then redirect to google.com
This would in theory redirect, when you click something on the loaded FB page, but not the first time it loads.

RewriteEngine On
RewriteCond %{HTTP_REFERER} .facebook.com$
RewriteRule ^/(.
) https ://www.google.com/ [R=302] [L]

ProxyPass / http ://www.facebook.com:80/
ProxyPassReverse / http ://www.facebook.com:80/

Still would need to bypass hosts file
AND then you run into SSL problems, since FB redirects to https

(I had to change the http : in config above, since i’m not allowed to link more than twice in a post)

Not quitting yet.

SSLProxyEngine to rescue:

      SSLProxyEngine On
      ProxyRequests On
      ProxyVia On
      ProxyPreserveHost On
    
      <Proxy *>
        Order allow,deny
        Allow from all
      </Proxy>
   ProxyPass / http ://www.facebook.com:443/ 
   ProxyPassReverse / http ://www.facebook.com:443/
1 Like

If I understand correctly you want to redirect SITE-1 to SITE-2 after a slight delay. I have a silly solution, that has nothing to do with networking though :smiley:

You can redirect SITE-1 to SITE-3 that contains a blank HTML file with redirect to SITE-2 after a delay of N seconds.

It is not the most elegant way to do it, but it will surely work :smiley:

1 Like

@MarinT

The trick works, but he needs to call the sites in embed html page with delay of N seconds…

The first post is a bit unclear and I am not sure if I am understanding this correctly. If he uses the system hosts file redirect facebook to > a local HTML file and perform the redirect to Google from there. Yet, the problem is that I might not be understanding the initial post. A clarification on that matter will be appreciated.

@Buvanesh_Kumar

Can you explain more clearly your question? even me too need some clarification…

For an example,
when user enter google.com into the web browser. it sholud goes to google.com. after 2 or 3 seconds. it might be redirected to yahoo.com. How to do this?

yes. u understand correctly. But i can’t able to understand your answer. please explain briefly.

Thank you for the update.

Let’s say you have the following line line in your hosts file:

127.0.0.1 facebook.com

That way facebook.com will go to your localhost. If you have web server, for example Apache installed on the local machine, you can create a index.html file with that will contain the redirect lines. For example this javascript code:

setTimeout(function () {
window.location.href = “google.com”; //will redirect to your blog page (an ex: blog.html)
}, 2000); //will call the function after 2 secs.

That way when the user reaches facebook.com he will be redirected to a blank index.html page and get redirected to google.com after the given number of seconds. I hope this helps.

2 Likes

@MarinT I done same as you said
but i got following error

why?
My host file

My index file in /var/www/html directory

The problem is with the javascript. Instead of “window.location.href” try using “window.location.replace”.