0

The originally intended title exceeds the limit; it is, "Why is a URL shortener rewriting http://cjsh.name to https://cjshayward.com when I want http://cjsh.name forwarded to https://cjshayward.com/books/?"

I posted below a question asked after long using Apache URL rewriting (from 1.3.x when 2.0 wasn't around). A quick check shows my /etc/apache2/sites-enabled to have 121 RewriteRules, including site relocation, switching from HTTP to HTTPS, and other workhorses. I'm also having trouble with a very simple task, simple as putting a RewriteRule to move something to another URL without breaking links or causing the old location to be a 404 error.

I also sanitized servers and identifiers, not because I'm relucant to give this specific raw data, but in an attempt at politeness, partly to avoid spam, and partly because someone can always ask to see the real data.

I have, modulo removing comments and hiding masking e.g. domain names, the following Apache VirtualHost:

<VirtualHost *:80>
        ServerAdmin cjshayward@pobox.com
        DocumentRoot /home/jonathan/stornge
        ServerName cjsh.name
        ServerAlias www.cjsh.name
        LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined
        CustomLog /home/jonathan/logs/stornge.com combined
        RewriteEngine on
        #RedirectMatch ^/$ https://cjshayward.com/books/
        RewriteRule ^/$ https://CJSHayward.com/books/ [R=301,L]
        RewriteRule ^$ https://CJSHayward.com/books/ [R=301,L]
        RewriteRule ^/([^?].*)$ http://stornge.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>
</VirtualHost>

I'm not sure this is anywhere near optimal; the reasons for involving two servers (for an external site not hosted on either server, three) are mostly historical that could be improved on.

However, I want http://cjsh.name to redirect to https://cjshayward.com/books/, and every time I load the homepage at http://cjsh.name, I am redirected to the homepage for https://cjshayward.com as a whole.

I can put the URI referral script in a pastebin if others want to see it, but I put what was meant as a "redirect from homepage" URL shortener:

#!/usr/bin/python 

import cgi
import cPickle
import os
import re
import sys

if (os.getenv('HTTP_HOST') in ['cjsh.name', 'www.cjsh.name', 'stornge.com',
  'www.stornge.com' and os.getenv('REQUEST_URI') ==
  os.getenv('SCRIPT_NAME')):
    print '''Status 301 Moved Permanently
Location: https://CJSHayward.com/books/
Content-Type: text/html; charset=UTF-8

<a href="https://CJSHayward.com/books/">Go to bookstore.</a>'''
    sys.exit(0)

I've tried a couple of ways of working around it, with clearing caches, switching between browsers, and using (sub)domains I haven't really used for anything else; I don't really use a FQDN of http://www.cjsh.name unless I was trying to circumvent caching expected in http://cjsh.name.

I do not consider this question to be, "How do you get things basically working with URLs and get work done," but "Why do my quite numerous attempts to redirect http://cjsh.name to https://cjshayward.com/books/ end up at the https://cjshayward.com homepage? These are two very different questions, so far as I know.

Christos Hayward
  • 1,152
  • 3
  • 15
  • 35
  • (Am I shooting myself in the foot by indenting things that shouldn't be indented?) – Christos Hayward Jul 25 '16 at 19:09
  • @TeroKilkanen Thank you; I posted a question about something focused rather than asking for a general sense of how one works with URL rewriting. – Christos Hayward Jul 25 '16 at 21:44
  • 3
    [We prefer real, non-obfuscated information when possible.](http://meta.serverfault.com/q/963/126632) So don't worry about that. As for your problem, Apache virtual hosts don't exist in a vacuum. The problem may be coming from elsewhere, such as the defaults, or an .htaccess file. – Michael Hampton Jul 25 '16 at 21:52
  • 4
    The linked question is a [canonical](http://meta.serverfault.com/q/1986/55514) one. These are questions where the community has said all it is going to say on a class of subject, because although everyone's particular problems in that class are somewhat different, to the extent that they are interesting, they aren't different, and to the extent that they're different, they aren't interesting (to anyone save the questioner). So we write one set of answers designed to be the last word on the subject, and say no more. – MadHatter Jul 25 '16 at 21:52

0 Answers0