From 7681ac2caef668e861c173d7a9209f74f82c0275 Mon Sep 17 00:00:00 2001
From: Owen Graham <ohgraham1@madisoncollege.edu>
Date: Mon, 13 Jun 2022 17:27:24 -0500
Subject: [PATCH] Set up redirect to new CGI script name
---
htdocs/.htaccess | 1 +
htdocs/visualizer.py | 15 +++++++++++++++
2 files changed, 16 insertions(+)
create mode 100755 htdocs/visualizer.py
diff --git a/htdocs/.htaccess b/htdocs/.htaccess
index f947f76..09db3f3 100644
--- a/htdocs/.htaccess
+++ b/htdocs/.htaccess
@@ -1,4 +1,5 @@
Options +ExecCGI
+AddHandler cgi-script .py
<FilesMatch "^-$">
SetHandler cgi-script
</FilesMatch>
diff --git a/htdocs/visualizer.py b/htdocs/visualizer.py
new file mode 100755
index 0000000..fa63eed
--- /dev/null
+++ b/htdocs/visualizer.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python3
+"""Redirect to the new CGI script name, "-"."""
+
+import os
+from pathlib import PurePosixPath
+
+request_script = PurePosixPath(os.getenv('SCRIPT_NAME'))
+request_uri = PurePosixPath(os.getenv('REQUEST_URI'))
+relative = request_uri.relative_to(request_script)
+target_script = request_script.with_name('-')
+target = target_script / relative
+
+print('Status: 308 Permanent Redirect')
+print(f'Location: {target}')
+print()
--
GitLab