root@technoluddites:/etc/apache2/sites-enabled# uname -a Linux technoluddites.org 4.19.0-9-amd64 #1 SMP Debian 4.19.118-2+deb10u1 (2020-06-07) x86_64 GNU/Linux root@technoluddites:/etc/apache2/sites-enabled# apachectl -v Server version: Apache/2.4.38 (Debian) Server built: 2019-10-15T19:53:42
I am trying to configure a site as a URL shortener. With exceptions, I am trying to get http://cjsh.name/foo to redirect to https://cjsh.name/?foo, and have an index.cgi that looks and sees if it has an entry for foo, and if not, redirect to https://cjshayward.com/foo. I tried to modify /index.cgi to log diagnostics to a file that isn't being opened; the beginning of /index.cgi reads:
#!/usr/bin/python import cgi import commands import cPickle import os import re import sys ADMIN_URL = u'/wp-content/protected/refer_url.cgi' CHARACTERS = \ u'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890' + \ u'=+/,!$*' DEFAULT_LOCATION = u'https://CJSHayward.com/' DEBUG_LOG = u'/tmp/cjsh.name.error' debug = open(DEBUG_LOG, 'w')
/tmp/cjsh.name.error is never being created, and an ls -ltu on the CGI script lists the time I last accessed the file from the command line, and not a time a few minutes later when I tried to load http://cjsh.name/pstv, which should hit a defined key in the dictionary and load https://cjshayward.com/positive/.
The HTTP site's Apache config file runs:
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /home/christos/books ServerName cjsh.name ServerAlias cjsh.cjshayward.com www.cjsh.name books.cjsh.name LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined CustomLog /home/christos/logs/cjsh.name combined ErrorLog /home/christos/logs/cjsh.name.error RewriteEngine on #RedirectMatch ^/$ https://cjshayward.com/ #RewriteRule ^/t-shirt$ https://www.zazzle.com/a_definion_of_the_autism_spectrum_t_shirt-235926361009257586 [R=301,L] #RewriteRule ^/$ https://CJSHayward.com/books/ [R=301,L] #RewriteRule ^$ https://CJSHayward.com/books/ [R=301,L] #RewriteRule ^/best.(.*)$ https://cjshayward.com/wp-content/cgi/download-ebook.cgi?book=The+Best+of+Jonathan%27s+Corner.$2 [R=301,L] RewriteRule ^/99.?[Pp][Aa][Gg][Ee].*$ https://smile.amazon.com/C-J-S-Hayward-Under-99-Pages/dp/B09H8SLCZP?_encoding=UTF8&qid=1632850210&sr=8-1&linkCode=ll1&tag=jonascorn-20&linkId=fffe9ae168e721fbc006f4096100e772&language=en_US&ref_=as_li_ss_tl [R=301,L] RewriteRule ^/phone\/?\.?% https://www.amazon.com/How-Take-Life-Back-Phone/dp/B0BHS7LQJV/ref=sr_1_1?crid=C9EYO4DANH6I&keywords=cjs+hayward+how+can+i+take+my+life+back+from+my+phone&qid=1670093200&sprefix=cjs+hayward+how+can+i+take+my+life+back+from+my+phonCapsC115&sr=8-1%23editorialReviews_feature_div [R=301,L] RewriteRule ^/([^\?].*)$ /?$1 [R=301,L] RewriteRule ^/$ https://cjshayward.com [R=301,L] #RewriteRule ^/(.*)$ https://cjshayward.com/$1 [R=301,L] #RewriteRule ^.*/writings/autobiography/(.*)$ /about/author/ [R=301,L] #RewriteRule ^/tiki.*$ http://www.facebook.com/pages/CJS-Hayward/9506801167 [R=301,L] #RewriteRule ^/community/tiki.*$ http://www.facebook.com/pages/CJS-Hayward/9506801167 [R=301,L] <Directory /home/jonathan/stornge/> Options ExecCGI Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> #RewriteCond %{SERVER_NAME} =cjsh.name [OR] #RewriteCond %{SERVER_NAME} =cjsh.cjshayward.com [OR] #RewriteCond %{SERVER_NAME} =books.cjsh.name [OR] #RewriteCond %{SERVER_NAME} =www.cjsh.name #RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] </VirtualHost>
The HTTPS site's entry is:
<IfModule mod_ssl.c> <VirtualHost *:443> ServerAdmin [email protected] DocumentRoot /home/christos/cjsh.name ServerName cjsh.name ServerAlias cjsh.cjshayward.com www.cjsh.name books.cjsh.name LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined CustomLog /home/christos/logs/cjsh.name combined ErrorLog /home/christos/logs/cjsh.name.error RewriteEngine on RewriteRule ^/best.(.*)$ https://cjshayward.com/wp-content/cgi/download-ebook.cgi?book=The+Best+of+Jonathan%27s+Corner.$2 [R=301,L] RewriteRule ^/99.?[Pp][Aa][Gg][Ee].*$ https://smile.amazon.com/C-J-S-Hayward-Under-99-Pages/dp/B09H8SLCZP?_encoding=UTF8&qid=1632850210&sr=8-1&linkCode=ll1&tag=jonascorn-20&linkId=fffe9ae168e721fbc006f4096100e772&language=en_US&ref_=as_li_ss_tl [R=301,L] RewriteRule ^/phone\/?\.?% https://www.amazon.com/How-Take-Life-Back-Phone/dp/B0BHS7LQJV/ref=sr_1_1?crid=C9EYO4DANH6I&keywords=cjs+hayward+how+can+i+take+my+life+back+from+my+phone&qid=1670093200&sprefix=cjs+hayward+how+can+i+take+my+life+back+from+my+phonCapsC115&sr=8-1%23editorialReviews_feature_div [R=301,L] #RedirectMatch ^/$ https://cjshayward.com/ # Some rewrite rules in this file were disabled on your HTTPS site, # because they have the potential to create redirection loops. # RewriteRule ^/t-shirt$ https://www.zazzle.com/a_definion_of_the_autism_spectrum_t_shirt-235926361009257586 [R=301,L] # RewriteRule ^/$ https://CJSHayward.com/books/ [R=301,L] # RewriteRule ^$ https://CJSHayward.com/books/ [R=301,L] RewriteRule ^/([^\?].*)$ /?$1 [R=301,L] RewriteRule ^/$ https://cjshayward.com [R=301,L] #RewriteRule ^/(.*)$ https://cjshayward.com/$1 [R=301,L] #RewriteRule ^.*/writings/autobiography/(.*)$ /about/author/ [R=301,L] #RewriteRule ^/tiki.*$ http://www.facebook.com/pages/CJS-Hayward/9506801167 [R=301,L] #RewriteRule ^/community/tiki.*$ http://www.facebook.com/pages/CJS-Hayward/9506801167 [R=301,L] <Directory /home/jonathan/stornge/> Options ExecCGI Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> #Include /etc/letsencrypt/options-ssl-apache.conf #SSLCertificateFile /etc/letsencrypt/live/cjsh.name-0001/fullchain.pem #SSLCertificateKeyFile /etc/letsencrypt/live/cjsh.name-0001/privkey.pem SSLCertificateFile /etc/letsencrypt/live/cjsh.name-0002/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/cjsh.name-0002/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf </VirtualHost> </IfModule>
In my main apache2.conf file I have:
DirectoryIndex index.cgi index.php index.shtml index.html
I am attempting to access the site via Firefox (119.0.1) on a Mac (12.6.9), and close all tabs to my site(s) and delete all browsing history forever to get a clean slate. Attempts to access http://cjsh.name/pstv are redirecting to https://cjshayward.com/pstv (this is and should be a 404 page), and I have restarted Apache since touching the sites-enabled file. I also tried pulling http://cjsh.name/pstv for a first time from Safari, and Safari is behaving exactly like Firefox, i.e. redirecting to a 404 page at https://cjshayward.com/pstv.
How am I directing fresh calls to http://cjsh.name/pstv to https://cjshayward.com/pstv (and https://cjsh.name/?pstv to https://cjshayward.com/?pstv)?
How should I be changing either or both of the Apache files or other setup so that the index.cgi is called, looks up the "right of the initial question mark" data, and redirects to (in this case) https://cjshayward.com/positive/?
Thanks,