0
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,

3
  • 1
    Please try to post shorter questions if you want more people to read them. For example, remove the commented-out lines, and try a smaller config that still does not work. Look in the log files to see what request was made; set the debug level for rewrite with LogLevel warn rewrite:trace8; test the url with curl -v instead of a browser, so you can see the real replies including any Location redirection. Commented Nov 16, 2023 at 13:49
  • @meuh, I've removed the commented out lines on my server and in the post. Thank you for the curl -v suggestion; curl -v https://cjsh.name/?pstv gives an Apache redirect to https://cjshayward.com?pstv. Commented Nov 16, 2023 at 19:24
  • Please don't put an "update" at the bottom of the question. Instead, fix your question so that it's accurate and uptodate. Does your update replace part of the previous text? If so, just replace it Commented Nov 16, 2023 at 20:33

1 Answer 1

1

/tmp/cjsh.name.error is never being created

This has very little really to do with Apache but everything to do with the way it's started, which I'm going to guess is with systemd. Take a look at the systemd configuration for Apache:

cat "$(find /etc/systemd/ -type f -iname '*apache*')" 

You will see this line, which tells systemd that /tmp is to be mapped to a private temporary directory instead of using the public /tmp:

PrivateTmp=true 

You can override this by running systemctl edit apache2 and adding these two lines,

[Service] PrivateTmp=false 

or if you need to see it just for debugging you can look for it,

find /tmp -type f -name cjsh.name.error 

But for intentionally accessible data files you should think carefully about other options, such as writing these not-so-temporary files to a place other than /tmp.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.