Skip to content

Instantly share code, notes, and snippets.

@m-242
Created March 26, 2020 10:54
Show Gist options
  • Select an option

  • Save m-242/1226349cf7395b0d21a5148a97d0b0c7 to your computer and use it in GitHub Desktop.

Select an option

Save m-242/1226349cf7395b0d21a5148a97d0b0c7 to your computer and use it in GitHub Desktop.
A stupid redirection looping server, because why rewrite it each time I use it ?
from http.server import HTTPServer, BaseHTTPRequestHandler
class redirectHandler(BaseHTTPRequestHandler):
def do_GET(self):
""" Looping redirections """
path = "/a" if self.path == "/b" else "/b"
self.send_response(301)
self.send_header("Location", path)
self.end_headers()
PORT = 80
print(f"serving at port {PORT}")
HTTPServer(("", PORT), redirectHandler).serve_forever()
@m-242

m-242 commented Mar 26, 2020

Copy link
Copy Markdown
Author

With the help of this answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment