I am working on a url redirector application, in Python. The idea of this application is simple: when a user performs an http request to a certain domain (e.g. to https://google.com), the app stops the request and performs another http request (e.g. to https://github.com), thereby redirecting the user to the second page.
Unfortunately, I have looked through SO and I haven't found any question that addresses this issue directly:
- Intercept and filter HTTP request doesn't redirect
- Sending a HTTP request using python doesn't either
Admittedly, I only have some fabricated pseudocode to demonstrate what I wish to do, but it may prove useful:
import requests
original_site = "https://google.com"
redirect_site = "https://github.com"
def redirect_request():
if requests.get(original_site) == True:
requests.kill(request.original_site.id)
requests.get(redirect_site)
I greatly appreciate any suggestions.
EDIT - Here is a clarification of what I mean:
The user runs my python script, which I will call foobar.py
, as follows:
python foobar.py
Then the user opens their web browser, and enters the url https://google.com, and as the script is running, the user will not actually visit https://google.com, but be redirected to https://github.com