0

after searching and try-and-erroring for a while I came to the conclusion that my problem is a bit too special for google :-)

I have 2 domains and multiple subs

example.org

  • cloud.example.org
  • wiki.example.org
  • *.example.org (all other to this domain) should redirect to example.org which shows the "under construction" image.

beispiel.de

  • blog.beispiel.de
  • same here: *.beispiel.de should redirect to beispiel.de

I have 1 file per subdomain with 1 vHost in my Apache conf. I use "Let's encrypt" for https.

 

Problems:

http://blupp.example.com goes to https://blupp.example.com and Firefox shows the connection not secure warning. After klicking Ignore, it redirects to the main page but with https://blupp.example.com in the URL.

-> Error It should go to example.com

 

Another Problem is:

example.com is my first page. So if sth. goes wrong at beispiel.de, it redirects to the first page: cloud.example.com

-> Error I dont want to mix example.com and beispiel.de, but only want to rent one server :-)

 

These are my files (order is important, I know :-)

0_redirects.conf Just make http requests -> https

<VirtualHost *:80>
    RewriteEngine On

    RewriteCond %{HTTPS} off
    RewriteRule "/" https://%{HTTP_HOST}%{REQUEST_URI}

</VirtualHost>

1_cloud-le-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>

    ServerAdmin admin@... 
    ServerName cloud.example.com
    ServerAlias cloud.example.com

    <Directory /var/www/example.com/cloud/>
        Require all granted
        AllowOverride All
        Options FollowSymLinks MultiViews
    </Directory>

    SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf  

</VirtualHost>
</IfModule>

Same for wiki.example.com and blog.beispiel.de, each with an incremented prefix number.

I first tried to get all example.com pages running, so I left beispiel.de untouched.

Now I tried many ways to create an additional vHost for both main domains that redirects evrything else to the correct main example or beispiel, but failed.

I tried to redirect

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName null
    ServerAlias *.example.com
    Redirect permanent / example.com

</VirtualHost>
</IfModule>

and set this config on a higher order position (100).

I don't know what to do here. Can someone help?

Best regards

Eddi

1 Answers1

0

The easiest solution to have your redirects working correctly for each sub-domain is to set them up in their own VirtualHost containers.

The second thing is to not use a parameterised mod_rewrite rule for your redirects, but as the manual recommends avoid mod_rewrite and use Redirect directives.

# Correctly redirect plain http requests -> https


<VirtualHost *:80>
    ServerName cloud.example.org
    Redirect "/" "https://cloud.example.org/"
</VirtualHost>

<VirtualHost *:80>
    ServerName wiki.example.org
    Redirect "/" "https://wiki.example.org/"
</VirtualHost>

<VirtualHost *:80>
    ServerName example.org
    ServerAlias *.example.org
    Redirect "/" "https://example.org/"
</VirtualHost>

and similarly for biespiel.de.

Take into account that for Apache HTTPD ServerName and ServerAlias matching is dependant on order and that first-match will be used with regards to Host: headers that match multiple VirtualHosts. No special priority is made for ServerAlias records containing a wildcard *. Therefore the explicit ServerName cloud.example.org VirtualHosts must be ordered before VirtualHost block containing the ServerAlias *.example.org wildcard.

HBruijn
  • 77,029
  • 24
  • 135
  • 201
  • Thanks, HBruijn, I will test it tonight So can I put the *:80 directives into my 0_redirects.conf file and use a single file for each *:433 vHost? – edwarddeath Mar 20 '23 at 13:26
  • Thanks, HBruijn again. It worked for both domains and all subdomains. It took me months, LOL... sometimes the less complicated solution is the best – edwarddeath Mar 20 '23 at 21:06