Skip to content

Instantly share code, notes, and snippets.

@iturdikulov
Forked from kwilczynski/fake-redirect.py
Created July 12, 2022 16:36
Show Gist options
  • Save iturdikulov/245b18ac893c1bf2fb834e220de0953f to your computer and use it in GitHub Desktop.
Save iturdikulov/245b18ac893c1bf2fb834e220de0953f to your computer and use it in GitHub Desktop.
Create a simple HTTP redirect with Python on localhost.
#!/usr/bin/env python3
# Redirect all requests to the given URL.
import SimpleHTTPServer
import SocketServer
class FakeRedirect(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
print(self.path)
self.send_response(301)
new_path = '%s%s' % ('http://localhost:40125', self.path)
self.send_header('Location', new_path)
self.end_headers()
if __name__ == '__main__':
SocketServer.TCPServer(("", 8080), FakeRedirect).serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment