Question

Domain B (http) is redirected to domain A (Https)

Hello I had a domain (domain A) running with let’s encrypt and correctly redirected from http to https, today I set up a new virtual host with another domain (domain B) with let’s encrypt too, but when I enter domain b with http (http: //domainb.com or http://www.dominiob.com) I am redirected to domain A with https, but I need that instead of being redirected to domain A go to domain B in https

I believe that de configuration is ok, but I don’t why don’t repect the redirection for domain B, these are the configurations:

Domain A.conf:

<VirtualHost *:80>
    ServerAdmin xxxxx@gmail.com
    ServerName domaina.com
    ServerAlias www.domaina.com
    DocumentRoot /var/www/domaina.com/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =domaina.com [OR]
RewriteCond %{SERVER_NAME} =www.domaina.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
<Directory /var/www/domaina.com/>
    AllowOverride All
</Directory>
</VirtualHost>

Domain A-le-ssl.conf:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerAdmin xxxxx@gmail.com
    ServerName domaina.com
    ServerAlias www.domaina.com
    DocumentRoot /var/www/domain.com/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/domaina.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domaina.com/privkey.pem
</VirtualHost>
</IfModule>

Domain B.conf:

<VirtualHost *:80>
    ServerAdmin info@XXXX.com
    ServerName domainb.com
    ServerAlias www.domainb.com
    DocumentRoot /var/www/domainb.com/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =domainb.com [OR]
RewriteCond %{SERVER_NAME} =www.domainb.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

<Directory /var/www/domainb.com/>
    AllowOverride All
</Directory>


</VirtualHost>

Domain B-le-ssl.conf:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerAdmin info@xxxxx.com
    ServerName domainb.com
    ServerAlias www.domainb.com
    DocumentRoot /var/www/domainb.com/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/domainb.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem
</VirtualHost>
</IfModule>

NOTE: When I use https://www.domainb.com or https://domainb.com the server load the right web, the problem is only with http://domain.com or http://www.domain.com.

Have someone ideas?

Show comments

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
June 27, 2019
Accepted Answer

Hello,

I had to fix a similar issue yesterday. The problem was that the Vhost for domainB.com for port 80 was missing.

However in your case the config indeed looks correct. As long as you have a Vhost for domainB.com for port 80 it should work fine.

Can you confirm if you have restarted apache after those changes?

Also can you check if you have a Varnish running on port 80 or similar service? If so try restarting that as well

Hope that this helps! Regards, Bobby

I have the same issue with my lamp stack. Appreciate you posting your issue (and your positive results).

Thanks!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel