Score:0

HTTP to HTTPS Redirection for Server Alias

ru flag

I have two sites; myFirstSite.123 and mySecondSite.456 and using the Server Alias to redirect accordingly. There two conf file on my Ubuntu Apache server as follows;

It works for myFirstSite.123 forwarded to its https. But mySecondSite.456 is forwarding to https://www.myFirstSite.123. Not to its corresponding site.

I tried changing rewrite rules but still not working.

How can I fix this?

<VirtualHost *:80>
    ServerName myFirstSite.123
    RewriteEngine on
    RewriteRule ^/(.*)$ https://%(HTTP_HOST}$1 [R=301,L]
</VirtualHost>


<IfModule mod_ssl.c>
<VirtualHost *:443>
   ServerAdmin webmaster@localhost
   ServerName myFirstSite.123
   ServerAlias www.myFirstSite.123
   ServerAlias mySecondSite.456
   ServerAlias www.mySecondSite.456

   DocumentRoot /var/www/da

   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined

   <Directory /var/www/da>
           DirectoryIndex index.php index.html
           Options Indexes FollowSymLinks MultiViews
           AllowOverride All
           Order allow,deny
           allow from all
    </Directory>

   Include /etc/letsencrypt/options-ssl-apache.conf

   SSLCertificateFile /etc/letsencrypt/live/myFirstSite.123/fullchain.pem
   SSLCertificateKeyFile /etc/letsencrypt/live/myFirstSite.123/privkey.pem
</VirtualHost>
</IfModule>
Nikita Kipriyanov avatar
za flag
Where is a HTTP (not HTTPS) virtualhost which would react on `mySecondSite.456`? Right now I see only the virtualhost for `myFirstSite.123`. Maybe not these vhosts, but e.g. default vhost reacts for that mySecondSite.456 host header and redirects to "primary" host name which is www.myFirstSite.123. What is in log files? Also, `RewriteRule ^/(.*)$ https://%(HTTP_HOST}$1 [R=301,L]` — are you sure delimiters around HTTP_HOST are of different kind? I think both of them must be curly brackets.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.