From 7b1c32eac2cd6c5b032b9b128e9557f01a5a4b2c Mon Sep 17 00:00:00 2001 From: pictuga Date: Tue, 16 Apr 2013 16:11:34 +0200 Subject: [PATCH] Added support for 404 redirect. ie. http://domain.com/bbc.co.uk/feed.xml will redirect to http://domain.com/morss.py/bbc.co.uk/feed.xml and work. --- .htaccess | 2 ++ morss.py | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.htaccess b/.htaccess index 7a206d3..f1e7962 100644 --- a/.htaccess +++ b/.htaccess @@ -1,2 +1,4 @@ AddHandler cgi-script .py Options +ExecCGI + +ErrorDocument 404 /morss.py diff --git a/morss.py b/morss.py index f032699..c501f80 100644 --- a/morss.py +++ b/morss.py @@ -349,9 +349,17 @@ def Gather(data, cachePath): if __name__ == "__main__": if SERVER: + print 'Status: 200' print 'Content-Type: text/html\n' - url = os.environ['REQUEST_URI'][len(os.environ['SCRIPT_NAME'])+1:] - url = 'http://' + url.replace(' ', '%20') + + if 'REDIRECT_URL' in os.environ: + url = os.environ['REQUEST_URI'][1:] + else: + url = os.environ['REQUEST_URI'][len(os.environ['SCRIPT_NAME'])+1:] + if not url.startswith('http://') and not url.startswith('https://'): + url = "http://" + url + url = url.replace(' ', '%20') + cache = os.getcwd() + '/cache' log(url) RSS = Gather(url, cache)