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 onhttps://www.zazzle.com/a_definion_of_the_autism_spectrum_t_shirt-235926361009257586 [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] <Directory /home/jonathan/stornge/> Options ExecCGI Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> </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] RewriteRule ^/([^\?].*)$ /?$1 [R=301,L] RewriteRule ^/$ https://cjshayward.com [R=301,L] <Directory /home/jonathan/stornge/> Options ExecCGI Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> 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 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/?
--UPDATE--
I shot myself in the foot by having cjsh.name ServerAliased in an earlier entry and that was producing the behavior I originally reported. However, the new difference in behavior is that trying to load http://cjsh.name/pstv loads https://cjshayward.com/?pstv instead of https://cjshayward.com/positive/. That happens to load the homepage rather than a 404 at https://cjshayward.com/pstv, but it is still an error and my homepage does not load the page at https://cjshayward.com/positive/.
Thanks,
LogLevel warn rewrite:trace8; test the url withcurl -vinstead of a browser, so you can see the real replies including any Location redirection.curl -v https://cjsh.name/?pstvgives an Apache redirect tohttps://cjshayward.com?pstv.